1.\" $NetBSD: semget.2,v 1.13 2002/10/01 18:10:45 wiz Exp $ 2.\" 3.\" Copyright (c) 1995 Frank van der Linden 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.\" 3. All advertising materials mentioning features or use of this software 15.\" must display the following acknowledgement: 16.\" This product includes software developed for the NetBSD Project 17.\" by Frank van der Linden 18.\" 4. The name of the author may not be used to endorse or promote products 19.\" derived from this software without specific prior written permission 20.\" 21.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 25.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 26.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31.\" 32.Dd August 25, 1999 33.Dt SEMGET 2 34.Os 35.Sh NAME 36.Nm semget 37.Nd get set of semaphores 38.Sh LIBRARY 39.Lb libc 40.Sh SYNOPSIS 41.Fd #include \*[Lt]sys/sem.h\*[Gt] 42.Ft int 43.Fn semget "key_t key" "int nsems" "int semflg" 44.Sh DESCRIPTION 45The 46.Fn semget 47system call returns the semaphore identifier associated with 48.Fa key . 49.Pp 50A new set containing 51.Fa nsems 52semaphores is created if either 53.Fa key 54is equal to 55.Dv IPC_PRIVATE , 56or 57.Fa key 58does not have a semaphore set associated with it and the 59.Dv IPC_CREAT 60bit is set in 61.Fa semflg . 62.Pp 63If a new set of semaphores is created, the data structure associated with it 64(the 65.Va semid_ds 66structure, see 67.Xr semctl 2 ) 68is initialized as follows: 69.Bl -bullet 70.It 71.Va sem_perm.cuid 72and 73.Va sem_perm.uid 74are set to the effective uid of the calling process. 75.It 76.Va sem_perm.gid 77and 78.Va sem_perm.cgid 79are set to the effective gid of the calling process. 80.It 81.Va sem_perm.mode 82is set to the lower 9 bits of 83.Fa semflg . 84.It 85.Va sem_nsems 86is set to the value of 87.Fa nsems . 88.It 89.Va sem_ctime 90is set to the current time. 91.It 92.Va sem_otime 93is set to 0. 94.El 95.Sh RETURN VALUES 96.Fn semget 97returns a non-negative semaphore identifier if successful. 98Otherwise, -1 is returned and 99.Va errno 100is set to reflect the error. 101.Sh ERRORS 102.Bl -tag -width Er 103.It Bq Er EACCES 104The caller has no permission to access a semaphore set already associated with 105.Fa key . 106.It Bq Er EEXIST 107Both 108.Dv IPC_CREAT 109and 110.Dv IPC_EXCL 111are set in 112.Fa semflg , 113and a semaphore set is already associated with 114.Fa key . 115.It Bq Er EINVAL 116.Va nsems 117is less than 0 or greater than the system limit for the number in a semaphore 118set. 119.Pp 120A semaphore set associated with 121.Fa key 122exists, but has fewer semaphores than the number specified in 123.Fa nsems . 124.It Bq Er ENOSPC 125A new set of semaphores could not be created because the system limit 126for the number of semaphores or the number of semaphore sets has been 127reached. 128.It Bq Er ENOENT 129.Dv IPC_CREAT 130is not set in 131.Fa semflg 132and no semaphore set associated with 133.Fa key 134was found. 135.El 136.Sh SEE ALSO 137.Xr semctl 2 , 138.Xr semop 2 , 139.Xr ftok 3 140.Sh STANDARDS 141The 142.Nm 143system call conforms to 144.St -xsh5 . 145.Sh HISTORY 146Semaphores appeared in the first release of 147.At V . 148