开发者

Subscribe to a file in /sys

Inotify won't trigger on file开发者_C百科-changes in /sys - what ways are there to subscribe to changes in there?


Events that change /sys are usually handled by udev. So, you can add udevd rules to handle the events or use libudev to access and monitor the sysfs. I just found some tutorial here: http://www.signal11.us/oss/udev/


Use udev and udev rules to get a notification to changes (hardware hotplug, drivers load, firmware load etc.) that are reflected in /sys.

See http://hackaday.com/2009/09/18/how-to-write-udev-rules/ for details


To be notified on a change on a /sys file or directory, I use the polling objects from python.

import select

poll_objet = select.poll()
fd_object = file("/sys/what_you_want_to_survey", "r")
poll_objet.register(fd_object) # I use the select.POLLPRI | select.POLLERR combination in my code ;)
result = poll_object.poll()

where result is a list of (fd, event) that were touched.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜