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?
# ipcs -s : To list the accessible semaphores. # ipcs -m : To lists the shared memories. # ipcs -m -i 425984 : To detailed information about an ipc facility(here for id-425984). # ipcs -m -l : To get the system limits for each ipc facility.
The sem_getvalue() function retrieves the value of a named or unnamed semaphore. If the current value of the semaphore is zero and there are threads waiting on the semaphore, a negative value is returned. The absolute value of this negative value is the number of threads waiting on the semaphore.
int sem_wait(sem_t *sem); To release or signal a semaphore, we use the sem_post function: int sem_post(sem_t *sem); A semaphore is initialised by using sem_init(for processes or threads) or sem_open (for IPC).
If you specify a non-zero value for the pshared argument, the semaphore can be shared between processes. If you specify the value zero, the semaphore can be shared among threads of the same process. The sem_open function establishes a connection between a named semaphore and the calling process.
"ipcs -p " can not show the semaphores of the process holding, that must be a bug, or it's a limit because it's hard to show. You have to query by yourslef.
Note: if the process just read semaphores, then you may cannot get such information via ipcs command.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With