| Skip Navigation Links | |
| Exit Print View | |
![]() | man pages section 2: System Calls Oracle Solaris 11 Information Library |
- semaphore control operations
#include <sys/types.h>#include <sys/ipc.h>#include <sys/sem.h>intsemctl(intsemid,intsemnum,intcmd...);
Thesemctl() function provides a variety of semaphore control operations as specifiedbycmd. The fourth argument is optional, depending upon the operation requested. If required, it is of typeunion semun, which mustbe explicitly declared by the application program.
union semun { int val; struct semid_ds *buf; ushort_t *array;} arg ;The permission required for a semaphore operation is given as {token}, wheretoken is the type of permission needed. The types of permissionare interpreted as follows:
00400 READ by user00200 ALTER by user00040 READ by group00020 ALTER by group00004 READ by others00002 ALTER by others
See theSemaphore Operation Permissions subsection of theDEFINITIONS section ofIntro(2) for moreinformation. The following semaphore operations as specified bycmd are executed with respectto the semaphore specified bysemid andsemnum.
Return the value of semval (seeIntro(2)). {READ}
Set the value ofsemval toarg.val. {ALTER} When this command is successfully executed, thesemadj value corresponding to the specified semaphore in all processes is cleared.
Return the value of(int) sempid. {READ}
Return the value ofsemncnt. {READ}
Return the value ofsemzcnt. {READ}
The following operations return and set, respectively, everysemval in the setof semaphores.
Placesemvals into array pointed to byarg.array. {READ}
Setsemvals according to the array pointed to byarg.array. {ALTER}. When this cmd is successfully executed, thesemadj values corresponding to each specified semaphore in all processes are cleared.
The following operations are also available.
Place the current value of each member of the data structure associated withsemid into the structure pointed to byarg.buf. The contents of this structure are defined inIntro(2). {READ}
Set the value of the following members of the data structure associated withsemid to the corresponding value found in the structure pointed to byarg.buf:
sem_perm.uidsem_perm.gidsem_perm.mode /* access permission bits only */
This command can be executed only by a process that has either the {PRIV_IPC_OWNER} privilege or an effective user ID equal to the value ofmsg_perm.cuid ormsg_perm.uid in the data structure associated withmsqid. Only a process with the {PRIV_SYS_IPC_CONFIG} privilege can raise the value ofmsg_qbytes.
Remove the semaphore identifier specified bysemid from the system and destroy the set of semaphores and data structure associated with it. This command can be executed only by a process that has the {PRIV_IPC_OWNER} privilege or an effective user ID equal to the value ofsem_perm.cuid orsem_perm.uid in the data structure associated withsemid.
Upon successful completion, the value returned depends oncmd as follows:
the value ofsemval
the value of(int) sempid
the value ofsemncnt
the value ofsemzcnt
All other successful completions return0; otherwise,-1 is returned anderrno is set to indicate the error.
Thesemctl() function will fail if:
Operation permission is denied to the calling process (seeIntro(2)).
The source or target is not a valid address in the user process.
Thesemid argument is not a valid semaphore identifier; thesemnum argument is less than 0 or greater thansem_nsems -1; or thecmd argument is not a valid command or isIPC_SET andsem_perm.uid orsem_perm.gid is not valid.
Thecmd argument is equal toIPC_RMID orIPC_SET, the effective user ID of the calling process is not equal to the value ofsem_perm.cuid orsem_perm.uid in the data structure associated withsemid, and {PRIV_IPC_OWNER} is not asserted in the effective set of the calling process.
Thecmd argument isIPC_STAT anduid orgid is too large to be stored in the structure pointed to byarg.buf.
Thecmd argument isSETVAL orSETALL and the value to whichsemval is to be set is greater than the system imposed maximum.
Seeattributes(5) for descriptions of the following attributes:
|
ipcs(1),Intro(2),semget(2),semop(2),attributes(5),privileges(5),standards(5)
Copyright © 2011, Oracle and/or its affiliates. All rights reserved.Legal Notices | ![]() ![]() |