Issue with semaphore implementation
I am trying to create a semaphore between two of my processes. Process tht created the semaphore got killed. Now i am unable to create the semaphore with the same key when i restart this process. i cannot restart my system . Is there any way tht the kernel destroys this "orphaned" semaphore, which is used by none of the processes.
|
I can think of four ways around this.
|
thnx wjevans 4 such a prompt reply.
Well i m a windows programmer basically, and i've just started with Linux. In windows these orphaned semaphores are automatically deleted when none of the process holds a handle for it. Is there any similar house keeping done by linux kernel. Can i set any kernel parameters to do the same. |
No, there are no Unix/Linux housekeeping arrangements for orphaned semaphores. This is a "feature", though in your case it doesn't work to your benefit. No kernel parameters, no nothing.
Record locking in Unix/Linux fills the bill. For any range of bytes in a file (even bytes which do not actually exist in the file), you can:
The best decription I've seen of this is in Advanced Programming in the UNIX Environment, by W. Richard Stevens (of happy memory). (That means he's dead now.) But you can get a pretty good description of record locking by doing: Code:
man fcntl |
All times are GMT -5. The time now is 11:17 PM. |