{
    "mode": "perldoc",
    "parameter": "IPC::Semaphore",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/IPC%3A%3ASemaphore/json",
    "generated": "2026-06-10T02:53:19Z",
    "synopsis": "use IPC::SysV qw(IPCPRIVATE SIRUSR SIWUSR IPCCREAT);\nuse IPC::Semaphore;\n$sem = IPC::Semaphore->new(IPCPRIVATE, 10, SIRUSR | SIWUSR | IPCCREAT);\n$sem->setall( (0) x 10);\n@sem = $sem->getall;\n$ncnt = $sem->getncnt;\n$zcnt = $sem->getzcnt;\n$ds = $sem->stat;\n$sem->remove;",
    "sections": {
        "NAME": {
            "content": "IPC::Semaphore - SysV Semaphore IPC object class\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use IPC::SysV qw(IPCPRIVATE SIRUSR SIWUSR IPCCREAT);\nuse IPC::Semaphore;\n\n$sem = IPC::Semaphore->new(IPCPRIVATE, 10, SIRUSR | SIWUSR | IPCCREAT);\n\n$sem->setall( (0) x 10);\n\n@sem = $sem->getall;\n\n$ncnt = $sem->getncnt;\n\n$zcnt = $sem->getzcnt;\n\n$ds = $sem->stat;\n\n$sem->remove;\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "A class providing an object based interface to SysV IPC semaphores.\n",
            "subsections": []
        },
        "METHODS": {
            "content": "new ( KEY , NSEMS , FLAGS )\nCreate a new semaphore set associated with \"KEY\". \"NSEMS\" is the number of semaphores in the\nset. A new set is created if\n\n*   \"KEY\" is equal to \"IPCPRIVATE\"\n\n*   \"KEY\" does not already have a semaphore identifier associated with it, and \"*FLAGS* &\nIPCCREAT\" is true.\n\nOn creation of a new semaphore set \"FLAGS\" is used to set the permissions. Be careful not to\nset any flags that the Sys V IPC implementation does not allow: in some systems setting\nexecute bits makes the operations fail.\n\ngetall\nReturns the values of the semaphore set as an array.\n\ngetncnt ( SEM )\nReturns the number of processes waiting for the semaphore \"SEM\" to become greater than its\ncurrent value\n\ngetpid ( SEM )\nReturns the process id of the last process that performed an operation on the semaphore\n\"SEM\".\n\ngetval ( SEM )\nReturns the current value of the semaphore \"SEM\".\n\ngetzcnt ( SEM )\nReturns the number of processes waiting for the semaphore \"SEM\" to become zero.\n\nid  Returns the system identifier for the semaphore set.\n\nop ( OPLIST )\n\"OPLIST\" is a list of operations to pass to \"semop\". \"OPLIST\" is a concatenation of smaller\nlists, each which has three values. The first is the semaphore number, the second is the\noperation and the last is a flags value. See semop(2) for more details. For example\n\n$sem->op(\n0, -1, IPCNOWAIT,\n1,  1, IPCNOWAIT\n);\n\nremove\nRemove and destroy the semaphore set from the system.\n\nset ( STAT )\nset ( NAME => VALUE [, NAME => VALUE ...] )\n\"set\" will set the following values of the \"stat\" structure associated with the semaphore\nset.\n\nuid\ngid\nmode (only the permission bits)\n\n\"set\" accepts either a stat object, as returned by the \"stat\" method, or a list of\n*name*-*value* pairs.\n\nsetall ( VALUES )\nSets all values in the semaphore set to those given on the \"VALUES\" list. \"VALUES\" must\ncontain the correct number of values.\n\nsetval ( N , VALUE )\nSet the \"N\"th value in the semaphore set to \"VALUE\"\n\nstat\nReturns an object of type \"IPC::Semaphore::stat\" which is a sub-class of \"Class::Struct\". It\nprovides the following fields. For a description of these fields see your system\ndocumentation.\n\nuid\ngid\ncuid\ncgid\nmode\nctime\notime\nnsems\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "IPC::SysV, Class::Struct, semget(2), semctl(2), semop(2)\n",
            "subsections": []
        },
        "AUTHORS": {
            "content": "Graham Barr <gbarr@pobox.com>, Marcus Holland-Moritz <mhx@cpan.org>\n",
            "subsections": []
        },
        "COPYRIGHT": {
            "content": "Version 2.x, Copyright (C) 2007-2013, Marcus Holland-Moritz.\n\nVersion 1.x, Copyright (c) 1997, Graham Barr.\n\nThis program is free software; you can redistribute it and/or modify it under the same terms as\nPerl itself.\n",
            "subsections": []
        }
    },
    "summary": "IPC::Semaphore - SysV Semaphore IPC object class",
    "flags": [],
    "examples": [],
    "see_also": [
        {
            "name": "semget",
            "section": "2",
            "url": "https://www.chedong.com/phpMan.php/man/semget/2/json"
        },
        {
            "name": "semctl",
            "section": "2",
            "url": "https://www.chedong.com/phpMan.php/man/semctl/2/json"
        },
        {
            "name": "semop",
            "section": "2",
            "url": "https://www.chedong.com/phpMan.php/man/semop/2/json"
        }
    ]
}