1IPC::Semaphore(3) User Contributed Perl Documentation IPC::Semaphore(3)
2
3
4
6 IPC::Semaphore - SysV Semaphore IPC object class
7
9 use IPC::SysV qw(IPC_PRIVATE S_IRUSR S_IWUSR IPC_CREAT);
10 use IPC::Semaphore;
11
12 $sem = IPC::Semaphore->new(IPC_PRIVATE, 10, S_IRUSR | S_IWUSR | IPC_CREAT);
13
14 $sem->setall( (0) x 10);
15
16 @sem = $sem->getall;
17
18 $ncnt = $sem->getncnt;
19
20 $zcnt = $sem->getzcnt;
21
22 $ds = $sem->stat;
23
24 $sem->remove;
25
27 A class providing an object based interface to SysV IPC semaphores.
28
30 new ( KEY , NSEMS , FLAGS )
31 Create a new semaphore set associated with "KEY". "NSEMS" is the
32 number of semaphores in the set. A new set is created if
33
34 · "KEY" is equal to "IPC_PRIVATE"
35
36 · "KEY" does not already have a semaphore identifier associated
37 with it, and "FLAGS & IPC_CREAT" is true.
38
39 On creation of a new semaphore set "FLAGS" is used to set the
40 permissions. Be careful not to set any flags that the Sys V IPC
41 implementation does not allow: in some systems setting execute bits
42 makes the operations fail.
43
44 getall
45 Returns the values of the semaphore set as an array.
46
47 getncnt ( SEM )
48 Returns the number of processes waiting for the semaphore "SEM" to
49 become greater than its current value
50
51 getpid ( SEM )
52 Returns the process id of the last process that performed an
53 operation on the semaphore "SEM".
54
55 getval ( SEM )
56 Returns the current value of the semaphore "SEM".
57
58 getzcnt ( SEM )
59 Returns the number of processes waiting for the semaphore "SEM" to
60 become zero.
61
62 id Returns the system identifier for the semaphore set.
63
64 op ( OPLIST )
65 "OPLIST" is a list of operations to pass to "semop". "OPLIST" is a
66 concatenation of smaller lists, each which has three values. The
67 first is the semaphore number, the second is the operation and the
68 last is a flags value. See semop(2) for more details. For example
69
70 $sem->op(
71 0, -1, IPC_NOWAIT,
72 1, 1, IPC_NOWAIT
73 );
74
75 remove
76 Remove and destroy the semaphore set from the system.
77
78 set ( STAT )
79 set ( NAME => VALUE [, NAME => VALUE ...] )
80 "set" will set the following values of the "stat" structure
81 associated with the semaphore set.
82
83 uid
84 gid
85 mode (only the permission bits)
86
87 "set" accepts either a stat object, as returned by the "stat"
88 method, or a list of name-value pairs.
89
90 setall ( VALUES )
91 Sets all values in the semaphore set to those given on the "VALUES"
92 list. "VALUES" must contain the correct number of values.
93
94 setval ( N , VALUE )
95 Set the "N"th value in the semaphore set to "VALUE"
96
97 stat
98 Returns an object of type "IPC::Semaphore::stat" which is a sub-
99 class of "Class::Struct". It provides the following fields. For a
100 description of these fields see your system documentation.
101
102 uid
103 gid
104 cuid
105 cgid
106 mode
107 ctime
108 otime
109 nsems
110
112 IPC::SysV, Class::Struct, semget(2), semctl(2), semop(2)
113
115 Graham Barr <gbarr@pobox.com>, Marcus Holland-Moritz <mhx@cpan.org>
116
118 Version 2.x, Copyright (C) 2007-2013, Marcus Holland-Moritz.
119
120 Version 1.x, Copyright (c) 1997, Graham Barr.
121
122 This program is free software; you can redistribute it and/or modify it
123 under the same terms as Perl itself.
124
125
126
127perl v5.32.1 2020-11-16 IPC::Semaphore(3)