Copyright (C) 2000-2012 |
Manpages SEMOPSection: Linux Programmer's Manual (2)Updated: 1993-11-01 Index Return to Main Contents NAMEsemop - semaphore operationsSYNOPSIS# include <sys/types.h> # include <sys/ipc.h> # include <sys/sem.h> int semop ( int semid, struct sembuf *sops, unsigned nsops ) DESCRIPTIONThe function performs operations on selected members of the semaphore set indicated by semid. Each of the nsops elements in the array pointed to by sops specify an operation to be performed on a semaphore by a struct sembuf including the following members:
Flags recognized in sem_flg are IPC_NOWAIT and SEM_UNDO. If an operation asserts SEM_UNDO, it will be undone when the process exits. The system call semantic assures that the operations will be performed if and only if all of them will succeed. Each operation is performed on the sem_num-th semaphore of the semaphore set - where the first semaphore of the set is semaphore 0 - and is one among the following three. If sem_op is a positive integer, the operation adds this value to semval. Furthermore, if SEM_UNDO is asserted for this operation, the system updates the process undo count for this semaphore. The operation always goes through, so no process sleeping can happen. The calling process must have alter permissions on the semaphore set. If sem_op is zero, the process must have read access permissions on the semaphore set. If semval is zero, the operation goes through. Otherwise, if IPC_NOWAIT is asserted in sem_flg, the system call fails (undoing all previous actions performed) with errno set to EAGAIN. Otherwise semzcnt is incremented by one and the process sleeps until one of the following occurs:
If sem_op is less than zero, the process must have alter permissions on the semaphore set. If semval is greater than or equal to the absolute value of sem_op, the absolute value of sem_op is subtracted by semval. Furthermore, if SEM_UNDO is asserted for this operation, the system updates the process undo count for this semaphore. Then the operation goes through. Otherwise, if IPC_NOWAIT is asserted in sem_flg, the system call fails (undoing all previous actions performed) with errno set to EAGAIN. Otherwise semncnt is incremented by one and the process sleeps until one of the following occurs:
In case of success, the sempid member of the structure sem for each semaphore specified in the array pointed to by sops is set to the process-ID of the calling process. Furthermore both sem_otime and sem_ctime are set to the current time. RETURN VALUEIf successful the system call returns 0, otherwise it returns -1 with errno indicating the error.ERRORSFor a failing return, errno will be set to one among the following values:
NOTESThe sem_undo structures of a process aren't inherited by its child on execution of a fork(2) system call. They are instead inherited by the substituting process resulting by the execution of the execve(2) system call.The followings are limits on semaphore set resources affecting a semop call:
The implementation has no intrinsic limits for the adjust on exit maximum value (SEMAEM), the system wide maximum number of undo structures (SEMMNU) and the per process maximum number of undo entries system parameters. BUGSThe system maintains a per process sem_undo structure for each semaphore altered by the process with undo requests. Those structures are free at process exit. One major cause for unhappiness with the undo mechanism is that it does not fit in with the notion of having an atomic set of operations an array of semaphores. The undo requests for an array and each semaphore therein may have been accumulated over many semopt calls. Should the process sleep when exiting, or should all undo operations be applied with the IPC_NOWAIT flag in effect? Currently those undo operations which go through immediately are applied, and those that require a wait are ignored silently. Thus harmless undo usage is guaranteed with private semaphores only.CONFORMING TOSVr4, SVID. SVr4 documents additional error conditions EINVAL, EFBIG, ENOSPC.SEE ALSOipc(5), semctl(2), semget(2)
IndexThis document was created by man2html, using the manual pages. Time: 01:55:03 GMT, January 21, 2025 |