{
    "mode": "info",
    "parameter": "IPC::Semaphore",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/info/IPC%3A%3ASemaphore/json",
    "generated": "2026-07-05T16:03:50Z",
    "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\nnumber of semaphores in the set. A new set is created if\n\no   \"KEY\" is equal to \"IPCPRIVATE\"\n\no   \"KEY\" does not already have a semaphore identifier associated\nwith it, and \"FLAGS & IPCCREAT\" is true.\n\nOn creation of a new semaphore set \"FLAGS\" is used to set the\npermissions.  Be careful not to set any flags that the Sys V IPC\nimplementation does not allow: in some systems setting execute bits\nmakes 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\nbecome greater than its current value\n\ngetpid ( SEM )\nReturns the process id of the last process that performed an\noperation on the semaphore \"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\nbecome 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\nconcatenation of smaller lists, each which has three values. The\nfirst is the semaphore number, the second is the operation and the\nlast 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\nassociated with the semaphore set.\n\nuid\ngid\nmode (only the permission bits)\n\n\"set\" accepts either a stat object, as returned by the \"stat\"\nmethod, or a list of name-value pairs.\n\nsetall ( VALUES )\nSets all values in the semaphore set to those given on the \"VALUES\"\nlist.  \"VALUES\" must contain 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-\nclass of \"Class::Struct\". It provides the following fields. For a\ndescription of these fields see your system documentation.\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\nunder the same terms as Perl itself.\n\nperl v5.34.0                      2026-06-23             IPC::Semaphore(3perl)",
            "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"
        }
    ]
}