Where is a named semaphore stored?

7,804

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 form sem.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/.

Share:
7,804

Related videos on Youtube

indietosh
Author by

indietosh

Software Engineer. Working as full stack web developer.

Updated on September 18, 2022

Comments

  • indietosh
    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?

  • Manu Kanthan
    Manu Kanthan over 5 years
    This 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.