views:

222

answers:

3

In userspace Linux, I have a process blocking on a semaphore, as found by strace. Once the error condition occurs, the blocking is repeatable, so there must be another process that holds the semaphore and did not release it.

Is there a way to know which other process is currently holding the semaphore?

ipcs lists the semaphore, so does /proc/sysvipc/sem. Where can I find info on the holding process?

A: 

Did you try

ipcs -p
Pascal Thivent
Does not seem to work with semaphore. I can see the key all right, but ipcs -p -s yields no output.
0x6adb015
+2  A: 

Semaphores aren't mutexes. You don't "hold" them. If the process is blocked, that means it's waiting for someone else to do an "up" or "V" operation on it in the future. There's no kernel tool that will tell you what the future behavior of software will be.

Andy Ross
+1  A: 

There may be an easier way but you can use the semctl() call with the GETPID cmd. That should return the process that executed the last semop() call for the semaphore. This may or may not be your rogue process but it is probably a good hint.

Duck