{
    "mode": "man",
    "parameter": "sem_overview",
    "section": "7",
    "url": "https://www.chedong.com/phpMan.php/man/sem_overview/7/json",
    "generated": "2026-08-09T03:19:48Z",
    "sections": {
        "NAME": {
            "content": "semoverview - overview of POSIX semaphores\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "POSIX semaphores allow processes and threads to synchronize their actions.\n\nA  semaphore  is  an integer whose value is never allowed to fall below zero.  Two operations\ncan be performed on semaphores: increment the  semaphore  value  by  one  (sempost(3));  and\ndecrement the semaphore value by one (semwait(3)).  If the value of a semaphore is currently\nzero, then a semwait(3) operation will block until the value becomes greater than zero.\n\nPOSIX semaphores come in two forms: named semaphores and unnamed semaphores.\n",
            "subsections": [
                {
                    "name": "Named semaphores",
                    "content": "A  named semaphore is identified by a name of the form /somename; that is, a null-ter‐\nminated string of up to NAMEMAX-4 (i.e., 251) characters  consisting  of  an  initial\nslash,  followed  by one or more characters, none of which are slashes.  Two processes\ncan operate on the same named semaphore by passing the same name to semopen(3).\n\nThe semopen(3) function creates a new named semaphore or opens an existing named sem‐\naphore.  After the semaphore has been opened, it can be operated on using  sempost(3)\nand  semwait(3).   When  a  process  has  finished  using  the  semaphore, it can use\nsemclose(3) to close the semaphore.  When all processes have finished using the sema‐\nphore, it can be removed from the system using semunlink(3).\n"
                },
                {
                    "name": "Unnamed semaphores (memory-based semaphores)",
                    "content": "An unnamed semaphore does not have a name.  Instead the semaphore is placed in  a  re‐\ngion  of memory that is shared between multiple threads (a thread-shared semaphore) or\nprocesses (a process-shared semaphore).  A thread-shared semaphore  is  placed  in  an\narea  of  memory  shared between the threads of a process, for example, a global vari‐\nable.  A process-shared semaphore must be placed in a shared memory  region  (e.g.,  a\nSystem  V  shared memory segment created using shmget(2), or a POSIX shared memory ob‐\nject built created using shmopen(3)).\n\nBefore being used, an unnamed semaphore must be initialized using seminit(3).  It can\nthen be operated on using sempost(3) and  semwait(3).   When  the  semaphore  is  no\nlonger required, and before the memory in which it is located is deallocated, the sem‐\naphore should be destroyed using semdestroy(3).\n\nThe  remainder of this section describes some specific details of the Linux implementation of\nPOSIX semaphores.\n"
                },
                {
                    "name": "Versions",
                    "content": "Before Linux 2.6, Linux supported only unnamed, thread-shared semaphores.  On a  system  with\nLinux 2.6 and a glibc that provides the NPTL threading implementation, a complete implementa‐\ntion of POSIX semaphores is provided.\n"
                },
                {
                    "name": "Persistence",
                    "content": "POSIX  named semaphores have kernel persistence: if not removed by semunlink(3), a semaphore\nwill exist until the system is shut down.\n"
                },
                {
                    "name": "Linking",
                    "content": "Programs using the POSIX semaphores API must be compiled with cc -pthread to link against the\nreal-time library, librt.\n"
                },
                {
                    "name": "Accessing named semaphores via the filesystem",
                    "content": "On Linux, named semaphores are created  in  a  virtual  filesystem,  normally  mounted  under\n/dev/shm,  with names of the form sem.somename.  (This is the reason that semaphore names are\nlimited to NAMEMAX-4 rather than NAMEMAX characters.)\n\nSince Linux 2.6.19, ACLs can be placed on files under this directory, to control object  per‐\nmissions on a per-user and per-group basis.\n"
                }
            ]
        },
        "NOTES": {
            "content": "System V semaphores (semget(2), semop(2), etc.) are an older semaphore API.  POSIX semaphores\nprovide  a simpler, and better designed interface than System V semaphores; on the other hand\nPOSIX semaphores are less widely available (especially on older systems) than System V  sema‐\nphores.\n",
            "subsections": []
        },
        "EXAMPLES": {
            "content": "An example of the use of various POSIX semaphore functions is shown in semwait(3).\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "semclose(3), semdestroy(3), semgetvalue(3), seminit(3), semopen(3), sempost(3), semun‐\nlink(3), semwait(3), pthreads(7), shmoverview(7)\n\nLinux man-pages 6.7                          2023-10-31                              semoverview(7)",
            "subsections": []
        }
    },
    "summary": "semoverview - overview of POSIX semaphores",
    "flags": [],
    "examples": [
        "An example of the use of various POSIX semaphore functions is shown in semwait(3)."
    ],
    "see_also": [
        {
            "name": "semclose",
            "section": "3",
            "url": "https://www.chedong.com/phpMan.php/man/semclose/3/json"
        },
        {
            "name": "semdestroy",
            "section": "3",
            "url": "https://www.chedong.com/phpMan.php/man/semdestroy/3/json"
        },
        {
            "name": "semgetvalue",
            "section": "3",
            "url": "https://www.chedong.com/phpMan.php/man/semgetvalue/3/json"
        },
        {
            "name": "seminit",
            "section": "3",
            "url": "https://www.chedong.com/phpMan.php/man/seminit/3/json"
        },
        {
            "name": "semopen",
            "section": "3",
            "url": "https://www.chedong.com/phpMan.php/man/semopen/3/json"
        },
        {
            "name": "sempost",
            "section": "3",
            "url": "https://www.chedong.com/phpMan.php/man/sempost/3/json"
        },
        {
            "name": "link",
            "section": "3",
            "url": "https://www.chedong.com/phpMan.php/man/link/3/json"
        },
        {
            "name": "semwait",
            "section": "3",
            "url": "https://www.chedong.com/phpMan.php/man/semwait/3/json"
        },
        {
            "name": "pthreads",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/pthreads/7/json"
        },
        {
            "name": "shmoverview",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/shmoverview/7/json"
        }
    ]
}