How to open a device for exclusive access?

Michael ODonnell michael.odonnell at comcast.net
Sat Jul 14 12:50:22 EDT 2007



>> One common method is for your servers to attempt
>> to open() an appropriately named file under
>> /var/lock/subsystem using O_EXCL|O_CREAT.
>
>I was hoping for something cleaner.  :-( Now I'd have to worry
>about the server leaving the file around if it aborts uncleanly.

Understood, and if you find a cleaner one I hope you'll mention it
here.  Meanwhile, this approach is common because it's an easy way
to take advantage of the mutex behavior inherent in the filesystem
ops in question, and you can store info (like your server's PID)
in the files so created to help you handle the unclean-exit cases.
 


More information about the gnhlug-discuss mailing list