Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display the process currently holding a semaphore?

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?

like image 780
0x6adb015 Avatar asked Sep 11 '09 13:09

0x6adb015


People also ask

How list current semaphore configuration details on Linux server?

# 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.

How do you find the value of semaphores?

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.

How do I run a semaphore program in Linux?

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).

How are semaphores used between processes?

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.


1 Answers

"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.

  1. run "ipcs -s" to get all semid
  2. for each semid run "ipcs -s -i "
  3. for each semnum, to get owner pid, if the owner pid is you wish, then show the current semid and semnum.

Note: if the process just read semaphores, then you may cannot get such information via ipcs command.

like image 97
Deli Zhang Avatar answered Oct 19 '22 23:10

Deli Zhang