| 1 |
.\" -*- mode: troff; coding: utf-8 -*- |
| 2 |
.\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45) |
| 3 |
.\" |
| 4 |
.\" Standard preamble: |
| 5 |
.\" ======================================================================== |
| 6 |
.de Sp \" Vertical space (when we can't use .PP) |
| 7 |
.if t .sp .5v |
| 8 |
.if n .sp |
| 9 |
.. |
| 10 |
.de Vb \" Begin verbatim text |
| 11 |
.ft CW |
| 12 |
.nf |
| 13 |
.ne \\$1 |
| 14 |
.. |
| 15 |
.de Ve \" End verbatim text |
| 16 |
.ft R |
| 17 |
.fi |
| 18 |
.. |
| 19 |
.\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. |
| 20 |
.ie n \{\ |
| 21 |
. ds C` "" |
| 22 |
. ds C' "" |
| 23 |
'br\} |
| 24 |
.el\{\ |
| 25 |
. ds C` |
| 26 |
. ds C' |
| 27 |
'br\} |
| 28 |
.\" |
| 29 |
.\" Escape single quotes in literal strings from groff's Unicode transform. |
| 30 |
.ie \n(.g .ds Aq \(aq |
| 31 |
.el .ds Aq ' |
| 32 |
.\" |
| 33 |
.\" If the F register is >0, we'll generate index entries on stderr for |
| 34 |
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index |
| 35 |
.\" entries marked with X<> in POD. Of course, you'll have to process the |
| 36 |
.\" output yourself in some meaningful fashion. |
| 37 |
.\" |
| 38 |
.\" Avoid warning from groff about undefined register 'F'. |
| 39 |
.de IX |
| 40 |
.. |
| 41 |
.nr rF 0 |
| 42 |
.if \n(.g .if rF .nr rF 1 |
| 43 |
.if (\n(rF:(\n(.g==0)) \{\ |
| 44 |
. if \nF \{\ |
| 45 |
. de IX |
| 46 |
. tm Index:\\$1\t\\n%\t"\\$2" |
| 47 |
.. |
| 48 |
. if !\nF==2 \{\ |
| 49 |
. nr % 0 |
| 50 |
. nr F 2 |
| 51 |
. \} |
| 52 |
. \} |
| 53 |
.\} |
| 54 |
.rr rF |
| 55 |
.\" ======================================================================== |
| 56 |
.\" |
| 57 |
.IX Title "IPC::Semaphore 3perl" |
| 58 |
.TH IPC::Semaphore 3perl 2025-11-16 "perl v5.40.1" "Perl Programmers Reference Guide" |
| 59 |
.\" For nroff, turn off justification. Always turn off hyphenation; it makes |
| 60 |
.\" way too many mistakes in technical documents. |
| 61 |
.if n .ad l |
| 62 |
.nh |
| 63 |
.SH NAME |
| 64 |
IPC::Semaphore \- SysV Semaphore IPC object class |
| 65 |
.SH SYNOPSIS |
| 66 |
.IX Header "SYNOPSIS" |
| 67 |
.Vb 2 |
| 68 |
\& use IPC::SysV qw(IPC_PRIVATE S_IRUSR S_IWUSR IPC_CREAT); |
| 69 |
\& use IPC::Semaphore; |
| 70 |
\& |
| 71 |
\& $sem = IPC::Semaphore\->new(IPC_PRIVATE, 10, S_IRUSR | S_IWUSR | IPC_CREAT); |
| 72 |
\& |
| 73 |
\& $sem\->setall( (0) x 10); |
| 74 |
\& |
| 75 |
\& @sem = $sem\->getall; |
| 76 |
\& |
| 77 |
\& $ncnt = $sem\->getncnt; |
| 78 |
\& |
| 79 |
\& $zcnt = $sem\->getzcnt; |
| 80 |
\& |
| 81 |
\& $ds = $sem\->stat; |
| 82 |
\& |
| 83 |
\& $sem\->remove; |
| 84 |
.Ve |
| 85 |
.SH DESCRIPTION |
| 86 |
.IX Header "DESCRIPTION" |
| 87 |
A class providing an object based interface to SysV IPC semaphores. |
| 88 |
.SH METHODS |
| 89 |
.IX Header "METHODS" |
| 90 |
.IP "new ( KEY , NSEMS , FLAGS )" 4 |
| 91 |
.IX Item "new ( KEY , NSEMS , FLAGS )" |
| 92 |
Create a new semaphore set associated with \f(CW\*(C`KEY\*(C'\fR. \f(CW\*(C`NSEMS\*(C'\fR is the number |
| 93 |
of semaphores in the set. A new set is created if |
| 94 |
.RS 4 |
| 95 |
.IP \(bu 4 |
| 96 |
\&\f(CW\*(C`KEY\*(C'\fR is equal to \f(CW\*(C`IPC_PRIVATE\*(C'\fR |
| 97 |
.IP \(bu 4 |
| 98 |
\&\f(CW\*(C`KEY\*(C'\fR does not already have a semaphore identifier |
| 99 |
associated with it, and \f(CW\*(C`\fR\f(CIFLAGS\fR\f(CW & IPC_CREAT\*(C'\fR is true. |
| 100 |
.RE |
| 101 |
.RS 4 |
| 102 |
.Sp |
| 103 |
On creation of a new semaphore set \f(CW\*(C`FLAGS\*(C'\fR is used to set the |
| 104 |
permissions. Be careful not to set any flags that the Sys V |
| 105 |
IPC implementation does not allow: in some systems setting |
| 106 |
execute bits makes the operations fail. |
| 107 |
.RE |
| 108 |
.IP getall 4 |
| 109 |
.IX Item "getall" |
| 110 |
Returns the values of the semaphore set as an array. |
| 111 |
.IP "getncnt ( SEM )" 4 |
| 112 |
.IX Item "getncnt ( SEM )" |
| 113 |
Returns the number of processes waiting for the semaphore \f(CW\*(C`SEM\*(C'\fR to |
| 114 |
become greater than its current value |
| 115 |
.IP "getpid ( SEM )" 4 |
| 116 |
.IX Item "getpid ( SEM )" |
| 117 |
Returns the process id of the last process that performed an operation |
| 118 |
on the semaphore \f(CW\*(C`SEM\*(C'\fR. |
| 119 |
.IP "getval ( SEM )" 4 |
| 120 |
.IX Item "getval ( SEM )" |
| 121 |
Returns the current value of the semaphore \f(CW\*(C`SEM\*(C'\fR. |
| 122 |
.IP "getzcnt ( SEM )" 4 |
| 123 |
.IX Item "getzcnt ( SEM )" |
| 124 |
Returns the number of processes waiting for the semaphore \f(CW\*(C`SEM\*(C'\fR to |
| 125 |
become zero. |
| 126 |
.IP id 4 |
| 127 |
.IX Item "id" |
| 128 |
Returns the system identifier for the semaphore set. |
| 129 |
.IP "op ( OPLIST )" 4 |
| 130 |
.IX Item "op ( OPLIST )" |
| 131 |
\&\f(CW\*(C`OPLIST\*(C'\fR is a list of operations to pass to \f(CW\*(C`semop\*(C'\fR. \f(CW\*(C`OPLIST\*(C'\fR is |
| 132 |
a concatenation of smaller lists, each which has three values. The |
| 133 |
first is the semaphore number, the second is the operation and the last |
| 134 |
is a flags value. See \fBsemop\fR\|(2) for more details. For example |
| 135 |
.Sp |
| 136 |
.Vb 4 |
| 137 |
\& $sem\->op( |
| 138 |
\& 0, \-1, IPC_NOWAIT, |
| 139 |
\& 1, 1, IPC_NOWAIT |
| 140 |
\& ); |
| 141 |
.Ve |
| 142 |
.IP remove 4 |
| 143 |
.IX Item "remove" |
| 144 |
Remove and destroy the semaphore set from the system. |
| 145 |
.IP "set ( STAT )" 4 |
| 146 |
.IX Item "set ( STAT )" |
| 147 |
.PD 0 |
| 148 |
.IP "set ( NAME => VALUE [, NAME => VALUE ...] )" 4 |
| 149 |
.IX Item "set ( NAME => VALUE [, NAME => VALUE ...] )" |
| 150 |
.PD |
| 151 |
\&\f(CW\*(C`set\*(C'\fR will set the following values of the \f(CW\*(C`stat\*(C'\fR structure associated |
| 152 |
with the semaphore set. |
| 153 |
.Sp |
| 154 |
.Vb 3 |
| 155 |
\& uid |
| 156 |
\& gid |
| 157 |
\& mode (only the permission bits) |
| 158 |
.Ve |
| 159 |
.Sp |
| 160 |
\&\f(CW\*(C`set\*(C'\fR accepts either a stat object, as returned by the \f(CW\*(C`stat\*(C'\fR method, |
| 161 |
or a list of \fIname\fR\-\fIvalue\fR pairs. |
| 162 |
.IP "setall ( VALUES )" 4 |
| 163 |
.IX Item "setall ( VALUES )" |
| 164 |
Sets all values in the semaphore set to those given on the \f(CW\*(C`VALUES\*(C'\fR list. |
| 165 |
\&\f(CW\*(C`VALUES\*(C'\fR must contain the correct number of values. |
| 166 |
.IP "setval ( N , VALUE )" 4 |
| 167 |
.IX Item "setval ( N , VALUE )" |
| 168 |
Set the \f(CW\*(C`N\*(C'\fRth value in the semaphore set to \f(CW\*(C`VALUE\*(C'\fR |
| 169 |
.IP stat 4 |
| 170 |
.IX Item "stat" |
| 171 |
Returns an object of type \f(CW\*(C`IPC::Semaphore::stat\*(C'\fR which is a sub-class of |
| 172 |
\&\f(CW\*(C`Class::Struct\*(C'\fR. It provides the following fields. For a description |
| 173 |
of these fields see your system documentation. |
| 174 |
.Sp |
| 175 |
.Vb 8 |
| 176 |
\& uid |
| 177 |
\& gid |
| 178 |
\& cuid |
| 179 |
\& cgid |
| 180 |
\& mode |
| 181 |
\& ctime |
| 182 |
\& otime |
| 183 |
\& nsems |
| 184 |
.Ve |
| 185 |
.SH "SEE ALSO" |
| 186 |
.IX Header "SEE ALSO" |
| 187 |
IPC::SysV, Class::Struct, \fBsemget\fR\|(2), \fBsemctl\fR\|(2), \fBsemop\fR\|(2) |
| 188 |
.SH AUTHORS |
| 189 |
.IX Header "AUTHORS" |
| 190 |
Graham Barr <[email protected]>, |
| 191 |
Marcus Holland-Moritz <[email protected]> |
| 192 |
.SH COPYRIGHT |
| 193 |
.IX Header "COPYRIGHT" |
| 194 |
Version 2.x, Copyright (C) 2007\-2013, Marcus Holland-Moritz. |
| 195 |
.PP |
| 196 |
Version 1.x, Copyright (c) 1997, Graham Barr. |
| 197 |
.PP |
| 198 |
This program is free software; you can redistribute it and/or |
| 199 |
modify it under the same terms as Perl itself. |