Home
Main website
Display Sidebar
Hide Ads
Recent Changes
View Source:
semop(2)
Edit
PageHistory
Diff
Info
LikePages
SEMOP !!!SEMOP NAME SYNOPSIS DESCRIPTION RETURN VALUE ERRORS NOTES BUGS CONFORMING TO SEE ALSO ---- !!NAME semop - semaphore operations !!SYNOPSIS __# include ____int semop ( int__ ''semid''__, struct sembuf *__''sops''__, unsigned__ ''nsops'' __)__ !!DESCRIPTION The 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: __short sem_num;__ /* semaphore number: 0 = first */__ short sem_op;__ /* semaphore operation */__ short sem_flg;__ /* operation flags */ 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: __semval__ becomes 0, at which time the value of __semzcnt__ is decremented. The semaphore set is removed: the system call fails with __errno__ set to __EIDRM__. The calling process receives a signal that has to be caught: the value of __semzcnt__ is decremented and the system call fails with __errno__ set to __EINTR__. 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: __semval__ becomes greater or equal to the absolute value of __sem_op__, at which time the value of __semncnt__ is decremented, the absolute value of __sem_op__ is subtracted from __semval__ and, if __SEM_UNDO__ is asserted for this operation, the system updates the process undo count for this semaphore. The semaphore set is removed from the system: the system call fails with __errno__ set to __EIDRM__. The calling process receives a signal that has to be caught: the value of __semncnt__ is decremented and the system call fails with __errno__ set to __EINTR__. 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 VALUE If successful the system call returns __0__, otherwise it returns __-1__ with __errno__ indicating the error. !!ERRORS For a failing return, __errno__ will be set to one among the following values: __E2BIG__ The argument ''nsops'' is greater than __SEMOPM__, the maximum number of operations allowed per system call. __EACCES__ The calling process has no access permissions on the semaphore set as required by one of the specified operations. __EAGAIN__ An operation could not go through and __IPC_NOWAIT__ was asserted in its ''sem_flg''__.__ __EFAULT__ The address pointed to by ''sops'' isn't accessible. __EFBIG__ For some operation the value of __sem_num__ is less than 0 or greater than or equal to the number of semaphores in the set. __EIDRM__ The semaphore set was removed. __EINTR__ Sleeping on a wait queue, the process received a signal that had to be caught. __EINVAL__ The semaphore set doesn't exist, or ''semid'' is less than zero, or ''nsops'' has a non-positive value. __ENOMEM__ The __sem_flg__ of some operation asserted __SEM_UNDO__ and the system has not enough memory to allocate the undo structure. __ERANGE__ For some operation __semop+semval__ is greater than __SEMVMX__, the implementation dependent maximum value for __semval__. !!NOTES The __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: __SEMOPM__ Maximum number of operations allowed for one __semop__ call: policy dependent. __SEMVMX__ Maximum allowable value for __semval__: implementation dependent (32767). 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. !!BUGS The 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 TO SVr4, SVID. SVr4 documents additional error conditions EINVAL, EFBIG, ENOSPC. !!SEE ALSO ipc(5), semctl(2), semget(2) ----
4 pages link to
semop(2)
:
ipc(2)
Man2s
ipc(5)
semget(2)
This page is a man page (or other imported legacy content). We are unable to automatically determine the license status of this page.