Home
Main website
Display Sidebar
Hide Ads
Recent Changes
View Source:
semctl(2)
Edit
PageHistory
Diff
Info
LikePages
!!NAME semctl - semaphore control operations !!SYNOPSIS __#include <sys/types.h>__ __#include <sys/ipc.h>__ __#include <sys/sem.h>__ __int semctl(int __''semid''__, int __''semnum''__, int __''cmd''__, ...);__ !!DESCRIPTION The function performs the control operation specified by ''cmd'' on the semaphore set (or on the ''semnum''-th semaphore of the set) identified by ''semid''. The first semaphore of the set is indicated by a value __0__ for ''semnum''. Legal values for ''cmd'' are ;__IPC_STAT__: Copy info from the semaphore set data structure into the structure pointed to by ''arg''__.buf__. The argument ''semnum'' is ignored. The calling process must have read access privileges on the semaphore set. ;__IPC_SET__: Write the values of some members of the __semid_ds__ structure pointed to by ''arg''__.buf__ to the semaphore set data structure, updating also its __sem_ctime__ member. Considered members from the user supplied __struct semid_ds__ pointed to by ''arg''__.buf__ are __ sem_perm.uid__ __sem_perm.gid__ __sem_perm.mode__ /* only lowest 9-bits */ ;:The calling process effective user-ID must be one among super-user, creator or owner of the semaphore set. The argument ''semnum'' is ignored. ;__IPC_RMID__: Remove immediately the semaphore set and its data structures awakening all waiting processes (with an error return and __errno__ set to __EIDRM__). The calling process effective user-ID must be one among super-user, creator or owner of the semaphore set. The argument ''semnum'' is ignored. ;__GETALL__: Return __semval__ for all semaphores of the set into ''arg''__.array__. The argument ''semnum'' is ignored. The calling process must have read access privileges on the semaphore set. ;__GETNCNT__: The system call returns the value of __semncnt__ for the ''semnum''-th semaphore of the set (i.e. the number of processes waiting for an increase of __semval__ for the ''semnum''-th semaphore of the set). The calling process must have read access privileges on the semaphore set. ;__GETPID__: The system call returns the value of __sempid__ for the ''semnum''-th semaphore of the set (i.e. the pid of the process that executed the last __semop__ call for the ''semnum''-th semaphore of the set). The calling process must have read access privileges on the semaphore set. ;__GETVAL__: The system call returns the value of __semval__ for the ''semnum''-th semaphore of the set. The calling process must have read access privileges on the semaphore set. ;__GETZCNT__: The system call returns the value of __semzcnt__ for the ''semnum''-th semaphore of the set (i.e. the number of processes waiting for __semval__ of the ''semnum''-th semaphore of the set to become 0). The calling process must have read access privileges on the semaphore set. ;__SETALL__: Set __semval__ for all semaphores of the set using ''arg''__.array__'','' updating also the __sem_ctime__ member of the __semid_ds__ structure associated to the set. Undo entries are cleared for altered semaphores in all processes. Processes sleeping on the wait queue are awakened if some __semval__ becomes 0 or increases. The argument ''semnum'' is ignored. The calling process must have alter access privileges on the semaphore set. ;__SETVAL__: Set the value of __semval__ to ''arg''__.val__ for the ''semnum''-th semaphore of the set, updating also the __sem_ctime__ member of the __semid_ds__ structure associated to the set. Undo entry is cleared for altered semaphore in all processes. Processes sleeping on the wait queue are awakened if __semval__ becomes 0 or increases. The calling process must have alter access privileges on the semaphore set. !!RETURN VALUE On fail the system call returns __-1__ with __errno__ indicating the error. Otherwise the system call returns a nonnegative value depending on ''cmd'' as follows: ;__GETNCNT__: The value of __semncnt__. ;__GETPID__: the value of __sempid__. ;__GETVAL__: the value of __semval__. ;__GETZCNT__: the value of __semzcnt__. !!ERRORS For a failing return, __errno__ will be set to one among the following values: ;[EACCES]: The calling process has no access permissions needed to execute ''cmd''. ;[EFAULT]: The address pointed to by ''arg''__.buf__ or ''arg''__.array__ isn't accessible. ;[EIDRM]: The semaphore set was removed. ;[EINVAL]: Invalid value for ''cmd'' or ''semid''. ;[EPERM]: The argument ''cmd'' has value __IPC_SET__ or __IPC_RMID__ but the calling process effective user-ID has insufficient privileges to execute the command. ;[ERANGE]: The argument ''cmd'' has value __SETALL__ or __SETVAL__ and the value to which __semval__ has to be set (for some semaphore of the set) is less than 0 or greater than the implementation value __SEMVMX__. !!NOTES The __IPC_INFO__, __SEM_STAT__ and __SEM_INFO__ control calls are used by the ipcs(8) program to provide information on allocated resources. In the future these can be modified as needed or moved to a proc file system interface. Various fields in a ''struct semid_ds'' were shorts under Linux 2.2 and have become longs under Linux 2.4. To take advantage of this, a recompilation under glibc-2.1.91 or later should suffice. (The kernel distinguishes old and new calls by a IPC_64 flag in ''cmd''.) The following system limit on semaphore sets affects a __semctl__ call: ;__SEMVMX__: Maximum value for __semval__: implementation dependent (32767). !!CONFORMING TO SVr4, SVID. SVr4 documents more error conditions [EINVAL] and [EOVERFLOW]. !!SEE ALSO ipc(5), shmget(2), shmat(2), shmdt(2)
5 pages link to
semctl(2)
:
ipc(2)
Man2s
ipc(5)
semget(2)
semop(2)
This page is a man page (or other imported legacy content). We are unable to automatically determine the license status of this page.