1.\" 2.\" Copyright (c) 1995 David Hovemeyer <daveho@infocom.com> 3.\" 4.\" All rights reserved. 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 2. Redistributions in binary form must reproduce the above copyright 12.\" notice, this list of conditions and the following disclaimer in the 13.\" documentation and/or other materials provided with the distribution. 14.\" 15.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR 16.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT, 19.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25.\" 26.\" $FreeBSD: src/lib/libc/sys/semctl.2,v 1.9.2.6 2002/03/11 08:37:47 maxim Exp $ 27.\" $DragonFly: src/lib/libc/sys/semctl.2,v 1.2 2003/06/17 04:26:47 dillon Exp $ 28.\" 29.Dd September 12, 1995 30.Dt SEMCTL 2 31.Os 32.Sh NAME 33.Nm semctl 34.Nd control operations on a semaphore set 35.Sh LIBRARY 36.Lb libc 37.Sh SYNOPSIS 38.In sys/types.h 39.In sys/ipc.h 40.In sys/sem.h 41.Ft int 42.Fn semctl "int semid" "int semnum" "int cmd" ... 43.Sh DESCRIPTION 44.Fn Semctl 45performs the operation indicated by 46.Fa cmd 47on the semaphore set indicated by 48.Fa semid . 49A fourth argument, a 50.Fa "union semun arg" , 51is required for certain values of 52.Fa cmd . 53For the commands that use the 54.Fa arg 55parameter, 56.Fa "union semun" 57is defined as follows: 58.Bd -literal 59.\" 60.\" From <sys/sem.h>: 61.\" 62union semun { 63 int val; /* value for SETVAL */ 64 struct semid_ds *buf; /* buffer for IPC_STAT & IPC_SET */ 65 u_short *array; /* array for GETALL & SETALL */ 66}; 67.Ed 68.Pp 69Commands are performed as follows: 70.\" 71.\" This section based on Stevens, _Advanced Programming in the UNIX 72.\" Environment_. 73.\" 74.Bl -tag -width IPC_RMIDXXX 75.It Dv IPC_STAT 76Fetch the semaphore set's 77.Fa "struct semid_ds" , 78storing it in the memory pointed to by 79.Fa arg.buf . 80.It Dv IPC_SET 81Changes the 82.Fa sem_perm.uid , 83.Fa sem_perm.gid , 84and 85.Fa sem_perm.mode 86members of the semaphore set's 87.Fa "struct semid_ds" 88to match those of the struct pointed to by 89.Fa arg.buf . 90The calling process's effective uid must 91match either 92.Fa sem_perm.uid 93or 94.Fa sem_perm.cuid , 95or it must have superuser privileges. 96.It IPC_RMID 97Immediately removes the semaphore set from the system. The calling 98process's effective uid must equal the semaphore set's 99.Fa sem_perm.uid 100or 101.Fa sem_perm.cuid , 102or the process must have superuser privileges. 103.It Dv GETVAL 104Return the value of semaphore number 105.Fa semnum . 106.It Dv SETVAL 107Set the value of semaphore number 108.Fa semnum 109to 110.Fa arg.val . 111.It Dv GETPID 112Return the pid of the last process to perform an operation on 113semaphore number 114.Fa semnum . 115.It Dv GETNCNT 116Return the number of processes waiting for semaphore number 117.Fa semnum Ns 's 118value to become greater than its current value. 119.It Dv GETZCNT 120Return the number of processes waiting for semaphore number 121.Fa semnum Ns 's 122value to become 0. 123.It Dv GETALL 124Fetch the value of all of the semaphores in the set into the 125array pointed to by 126.Fa arg.array . 127.It Dv SETALL 128Set the values of all of the semaphores in the set to the values 129in the array pointed to by 130.Fa arg.array . 131.El 132.Pp 133The 134.Fa "struct semid_ds" 135is defined as follows: 136.Bd -literal 137.\" 138.\" Taken straight from <sys/sem.h>. 139.\" 140struct semid_ds { 141 struct ipc_perm sem_perm; /* operation permission struct */ 142 struct sem *sem_base; /* pointer to first semaphore in set */ 143 u_short sem_nsems; /* number of sems in set */ 144 time_t sem_otime; /* last operation time */ 145 long sem_pad1; /* SVABI/386 says I need this here */ 146 time_t sem_ctime; /* last change time */ 147 /* Times measured in secs since */ 148 /* 00:00:00 GMT, Jan. 1, 1970 */ 149 long sem_pad2; /* SVABI/386 says I need this here */ 150 long sem_pad3[4]; /* SVABI/386 says I need this here */ 151}; 152.Ed 153.Sh RETURN VALUES 154On success, when 155.Fa cmd 156is one of 157.Dv GETVAL , GETPID , GETNCNT 158or 159.Dv GETZCNT , 160.Fn semctl 161returns the corresponding value; otherwise, 0 is returned. 162On failure, -1 is returned, and 163.Va errno 164is set to indicate the error. 165.Sh ERRORS 166.Fn Semctl 167will fail if: 168.Bl -tag -width Er 169.It Bq Er EINVAL 170No semaphore set corresponds to 171.Fa semid . 172.It Bq Er EINVAL 173.Fa semnum 174is not in the range of valid semaphores for given semaphore set. 175.It Bq Er EPERM 176The calling process's effective uid does not match the uid of 177the semaphore set's owner or creator. 178.It Bq Er EACCES 179Permission denied due to mismatch between operation and mode of 180semaphore set. 181.El 182.Sh SEE ALSO 183.Xr semget 2 , 184.Xr semop 2 185