4

inotify doesnt work on /sys and /proc file systems. So how can I monitor a /sys partition file without polling?

Abhijeet Rastogi
  • 3,497
  • 5
  • 33
  • 43

1 Answers1

2

What kind of polling? Do you mean a sleep/check loop? Or do you mean the poll system call as documented in man 2 poll?

According to a 2009 email from kernel developer Greg KH, the best option is to use select. See man 2 select for details. Note that the poll system call is basically the same as this.

On the other hand, the current inotify FAQ suggests it might work.

Why not try it and find out?

Mikel
  • 8,846
  • 1
  • 41
  • 37
  • I think we can safely assume the OP was working from a shell and he wasn't talking about C functions. Anyway, currently it's still not working for me in /sys files (Linux 3.6.3), I only get OPEN/ACCESS events, but not changes made by the kernel. – tokland May 23 '13 at 17:56
  • @tokland I'm not aware of any command called `inotify`? – Mikel May 24 '13 at 01:26
  • FWIW, `inotifywatch` from `inotify-tools` seems to work fine to count changes on `/proc/sys` on my Linux 3.5.0 system. – Mikel May 24 '13 at 01:35
  • 3
    Mikel, I use `inotifywait` from `inotify-tools`. Can you try this in a laptop? `inotifywait -m /sys/class/power_supply/BAT0/status`. I get I don't get any event when this value changes (unplug/plug the battery). – tokland May 24 '13 at 07:58