1.\" $NetBSD: semget.2,v 1.1 1995/10/16 23:49:27 jtc 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 17, 1995 33.Dt SEMGET 2 34.Os NetBSD 35.Sh NAME 36.Nm semget 37.Nd get semaphore set 38.Sh SYNOPSIS 39.Fd #include <sys/types.h> 40.Fd #include <sys/ipc.h> 41.Fd #include <sys/sem.h> 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 50A new set containing 51.Fa nsems 52semaphores is created if either 53.Fa key 54is equal to IPC_PRIVATE, or 55.Fa key 56does not have a semaphore set associated with it, and the IPC_CREAT bit is 57set in 58.Fa msgflg. 59 60If a new set of semaphores is created, the data structure associated with it 61(the 62.Va semid_ds 63structure, see 64.Xr semctl 2 ) 65is intialized as follows: 66.Bl -bullet 67.It 68.Va sem_perm.cuid 69and 70.Va sem_perm.uid 71are set to the effective uid of the calling process. 72.It 73.Va sem_perm.gid 74and 75.Va sem_perm.cgid 76are set to the effective gid of the calling process. 77.It 78.Va sem_perm.mode 79is set to the lower 9 bits of 80.Fa msgflg . 81.It 82.Va sem_nsems 83is set to the value of 84.Fa nsems 85.It 86.Va sem_ctime 87is set to the current time 88.It 89.Va sem_otime 90is set to 0 91.El 92.Sh RETURN VALUES 93.Fn semget 94returns a non-negative semaphore identifier if successful. Otherwise, -1 95is returned and 96.Va errno 97is set to reflect the error. 98.Sh ERRORS 99.Bl -tag -width Er 100.It Bq Er EACCESS 101The caller has no permission to access a semaphore set already associated with 102.Fa key. 103.It Bq Er EEXIST 104Both IPC_CREAT and IPC_EXCL are set in 105.Fa msgflg , 106and a semaphore set is already associated with 107.Fa key . 108.It Bq Er EINVAL 109.Va nsems 110is less than 0 or greater than the system limit for the number in a semaphore 111set. 112 113A semaphore set associated with 114.Fa key 115exists, but has fewer semaphores than the number specified in 116.Fa nsems . 117.It Bq Er ENOSPC 118A new set of semaphores could not be created because the system limit 119for the number of semaphores or the number of semaphore sets has been 120reached. 121.It Bq Er ENOENT 122IPC_CREAT was not set in 123.Fa msgflg 124and no semaphore set associated with 125.Fa key 126was found. 127.El 128.Sh SEE ALSO 129.Xr semop 2 130.Xr semctl 2 131