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:
- set a reader's lock, and return if that cannot be done immediately;
- set a reader's lock, waiting until it can be done if necessary and not returning until it has been done;
- do the same things for a writer's lock;
- release a lock; and
- test the state of a lock without changing it.
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:
Hope this helps.