LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   watch for changes of /proc/partitions with select/pselect (https://www.linuxquestions.org/questions/programming-9/watch-for-changes-of-proc-partitions-with-select-pselect-902798/)

Pemek 09-13-2011 10:51 AM

watch for changes of /proc/partitions with select/pselect
 
Hi all,

I have to find the best way to watch for changes in list of disk devices and signal my server that sth has changed.
My first guess is to create a udev rule but I am not allowed to modify system files.
Second idea is to watch /proc/partitions for any changes. To do so I used select or pselect. It is very useful for watching changes of various files but it seems that /proc/partitions is always "changed" ie. ready to read the contents.
I use (p)select quite often so I am sure it is used in good manner (and works for other files).
What's wrong? Maybe /proc/partitions can't be 'watched' like this? If so, what is other simple way to watch for disk insert/removal.

My program is in C with standard library, and OpenSuse/RHEL as linux host.

Pemek

ta0kira 09-13-2011 05:46 PM

You might be able to monitor /dev with inotify, then check for new or deleted block devices when a notification comes.
Kevin Barry

Pemek 09-21-2011 09:07 AM

I have handled my case with inotify on /dev/disk/by-path which best suits me.
Seems like sysfs and procfs in general cannot be watched by poll/select and p* versions - drivers do not handle events and update filed on read request (with some exceptions like /proc/mdstat).

Thanks anyway, I was thinking about inotify but I wasn't sure. Now I am:)

Pemek


All times are GMT -5. The time now is 08:11 PM.