How to open a device for exclusive access?

Steven W. Orr steveo at syslang.net
Sat Jul 14 09:20:44 EDT 2007


On Friday, Jul 13th 2007 at 23:26 -0400, quoth Michael ODonnell:

=>
=>
=>One common method is for your servers to
=>attempt to open() an appropriately named file under
=>/var/lock/subsystem using O_EXCL|O_CREAT.  If that
=>fails you can assume another instance is already
=>running and has already claimed the corresponding /dev
=>entry.  Remember to delete your lock files on exit...

I was hoping for something cleaner. :-( Now I'd have to worry about the 
server leaving the file around if it aborts uncleanly. The other idea is a 
(ick) SV semaphore which releases if the process dies but... 

-- 
Time flies like the wind. Fruit flies like a banana. Stranger things have  .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net


More information about the gnhlug-discuss mailing list