LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-13-2011, 10:51 AM   #1
Pemek
LQ Newbie
 
Registered: Apr 2009
Posts: 4

Rep: Reputation: 0
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
 
Old 09-13-2011, 05:46 PM   #2
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
You might be able to monitor /dev with inotify, then check for new or deleted block devices when a notification comes.
Kevin Barry
 
1 members found this post helpful.
Old 09-21-2011, 09:07 AM   #3
Pemek
LQ Newbie
 
Registered: Apr 2009
Posts: 4

Original Poster
Rep: Reputation: 0
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
/proc/partitions does not exist Impaler Linux - Software 5 12-10-2008 10:54 PM
/proc/partitions showing wrong partitions netstv Linux - General 1 07-10-2006 01:11 PM
select partitions or format during install junme Solaris / OpenSolaris 4 12-24-2004 06:13 AM
/proc/partitions sighini Linux - General 0 11-17-2003 03:32 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:24 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration