semop

semopKEY,OPSTRING
This function calls the System V IPC syscall
semop(2) to do semaphore operations such as
signalling and waiting. Before calling, you should use IPC::SysV to get the correct constant definitions.
OPSTRING must be a packed array of
semop structures. You can make each
semop structure by saying pack("s*", $semnum, $semop, $semflag). The
number of semaphore operations is implied by the length of
OPSTRING. The function returns true if
successful, or false if there is an error.
The following code waits on semaphore $semnum of semaphore id $semid:
$semop = pack "s*", $semnum, –1, 0; semop($semid, $semop) || die "Semaphore trouble: $!";
To signal the semaphore, simply replace –1 with 1.
See the section System V IPC in Chapter 15. See also the
IPC::Semaphore module. This function is available only on machines
supporting System V IPC.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access