Where is a named semaphore stored?
Solution 1
From man 7 sem_overview :
Accessing named semaphores via the filesystem
On Linux, named semaphores are created in a virtual filesystem, normally mounted under
/dev/shm
, with names of the formsem.somename
. (This is the reason that semaphore names are limited to NAME_MAX-4 rather than NAME_MAX characters.)
Solution 2
/proc/<pid>/maps/
will show you the memory mapping of a process with a specific PID. (Related question: https://stackoverflow.com/questions/1401359/understanding-linux-proc-id-maps)
From the output, POSIX semaphores are shown as files in /dev/shm/
.
Related videos on Youtube
indietosh
Software Engineer. Working as full stack web developer.
Updated on September 18, 2022Comments
-
indietosh over 1 year
A named semaphore (using
semaphore.h
) is identified by a name in the form/somename
; that is, a null-terminated string of up to NAME_MAX-4 (i.e., 251) characters consisting of an initial slash, followed by one or more characters, none of which are slashes.As the name corresponds to pathname in filesystem. Where is this semaphore located?
ipcs
is for System V semaphores.How to locate POSIX semaphores?-
Admin about 8 yearsPlease do not post identical questions to multiple Stack Exchange sites. This question can be found on Stack Overflow.
-
-
Manu Kanthan over 5 yearsThis answer is a verbatim copy from
man 7 sem_overview
: man7.org/linux/man-pages/man7/sem_overview.7.html and should be annotated as such.