I could be wrong, but I'm thinking that you might be gathering different semaphore-handling functions from different sets of such functions.
My advice (which may be worthless) is that you pick one set of such semaphore-handling functions and remain with that set. You can find one such set by doing:
You can find another such set by doing:
Code:
man semctl
man semget
man semop
It doesn't sound like this is answering your questions, but I suspect that if you follow this advice, your problem will disappear.
Semaphores can be tricky. If your program blows up, often you have extra semaphores lying around which no one is using. So I'd go with (and have gone with) file record locking instead.
Hope this helps a little.