1IPC::Semaphore(3pm) Perl Programmers Reference Guide IPC::Semaphore(3pm)
2
3
4
6 IPC::Semaphore - SysV Semaphore IPC object class
7
9 use IPC::SysV qw(IPC_PRIVATE S_IRWXU IPC_CREAT);
10 use IPC::Semaphore;
11
12 $sem = new IPC::Semaphore(IPC_PRIVATE, 10, S_IRWXU ⎪ 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 associ‐
37 ated with it, and "FLAGS & IPC_CREAT" is true.
38
39 On creation of a new semaphore set "FLAGS" is used to set the per‐
40 missions.
41
42 getall
43 Returns the values of the semaphore set as an array.
44
45 getncnt ( SEM )
46 Returns the number of processes waiting for the semaphore "SEM" to
47 become greater than its current value
48
49 getpid ( SEM )
50 Returns the process id of the last process that performed an opera‐
51 tion on the semaphore "SEM".
52
53 getval ( SEM )
54 Returns the current value of the semaphore "SEM".
55
56 getzcnt ( SEM )
57 Returns the number of processes waiting for the semaphore "SEM" to
58 become zero.
59
60 id Returns the system identifier for the semaphore set.
61
62 op ( OPLIST )
63 "OPLIST" is a list of operations to pass to "semop". "OPLIST" is a
64 concatenation of smaller lists, each which has three values. The
65 first is the semaphore number, the second is the operation and the
66 last is a flags value. See semop for more details. For example
67
68 $sem->op(
69 0, -1, IPC_NOWAIT,
70 1, 1, IPC_NOWAIT
71 );
72
73 remove
74 Remove and destroy the semaphore set from the system.
75
76 set ( STAT )
77 set ( NAME => VALUE [, NAME => VALUE ...] )
78 "set" will set the following values of the "stat" structure associ‐
79 ated with the semaphore set.
80
81 uid
82 gid
83 mode (only the permission bits)
84
85 "set" accepts either a stat object, as returned by the "stat"
86 method, or a list of name-value pairs.
87
88 setall ( VALUES )
89 Sets all values in the semaphore set to those given on the "VALUES"
90 list. "VALUES" must contain the correct number of values.
91
92 setval ( N , VALUE )
93 Set the "N"th value in the semaphore set to "VALUE"
94
95 stat
96 Returns an object of type "IPC::Semaphore::stat" which is a sub-
97 class of "Class::Struct". It provides the following fields. For a
98 description of these fields see your system documentation.
99
100 uid
101 gid
102 cuid
103 cgid
104 mode
105 ctime
106 otime
107 nsems
108
110 IPC::SysV Class::Struct semget semctl semop
111
113 Graham Barr <gbarr@pobox.com>
114
116 Copyright (c) 1997 Graham Barr. All rights reserved. This program is
117 free software; you can redistribute it and/or modify it under the same
118 terms as Perl itself.
119
120
121
122perl v5.8.8 2001-09-21 IPC::Semaphore(3pm)