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$ 27.\" 28.Dd September 12, 1995 29.Dt SEMGET 2 30.Os 31.Sh NAME 32.Nm semget 33.Nd obtain a semaphore id 34.Sh LIBRARY 35.Lb libc 36.Sh SYNOPSIS 37.In sys/types.h 38.In sys/ipc.h 39.In sys/sem.h 40.Ft int 41.Fn semget "key_t key" "int nsems" "int flag" 42.Sh DESCRIPTION 43Based on the values of 44.Fa key 45and 46.Fa flag , 47.Fn semget 48returns the identifier of a newly created or previously existing 49set of semaphores. 50.\" 51.\" This is copied verbatim from the shmget manpage. Perhaps 52.\" it should go in a common manpage, such as .Xr ipc 2 53.\" 54The key 55is analogous to a filename: it provides a handle that names an 56IPC object. 57There are three ways to specify a key: 58.Bl -bullet 59.It 60IPC_PRIVATE may be specified, in which case a new IPC object 61will be created. 62.It 63An integer constant may be specified. 64If no IPC object corresponding 65to 66.Fa key 67is specified and the IPC_CREAT bit is set in 68.Fa flag , 69a new one will be created. 70.It 71The 72.Xr ftok 3 73function 74may be used to generate a key from a pathname. 75.El 76.\" 77.\" Likewise for this section, except SHM_* becomes SEM_*. 78.\" 79.Pp 80The mode of a newly created IPC object is determined by 81.Em OR Ns 'ing 82the following constants into the 83.Fa flag 84argument: 85.Bl -tag -width XSEM_WXX6XXX 86.It Dv SEM_R 87Read access for user. 88.It Dv SEM_A 89Alter access for user. 90.It Dv ( SEM_R>>3 ) 91Read access for group. 92.It Dv ( SEM_A>>3 ) 93Alter access for group. 94.It Dv ( SEM_R>>6 ) 95Read access for other. 96.It Dv ( SEM_A>>6 ) 97Alter access for other. 98.El 99.Pp 100If a new set of semaphores is being created, 101.Fa nsems 102is used to indicate the number of semaphores the set should contain. 103Otherwise, 104.Fa nsems 105may be specified as 0. 106.Sh RETURN VALUES 107The 108.Fn semget 109system call 110returns the id of a semaphore set if successful; otherwise, -1 111is returned and 112.Va errno 113is set to indicate the error. 114.Sh ERRORS 115The 116.Fn semget 117system call 118will fail if: 119.Bl -tag -width Er 120.\" ipcperm could fail (we are opening to read and write, as it were) 121.It Bq Er EACCES 122Access permission failure. 123.\" 124.\" sysv_sem.c is quite explicit about these, so I'm pretty sure 125.\" this is accurate 126.\" 127.It Bq Er EEXIST 128IPC_CREAT and IPC_EXCL were specified, and a semaphore set 129corresponding to 130.Fa key 131already exists. 132.It Bq Er EINVAL 133The number of semaphores requested exceeds the system imposed maximum 134per set. 135.It Bq Er ENOSPC 136Insufficiently many semaphores are available. 137.It Bq Er ENOSPC 138The kernel could not allocate a 139.Fa "struct semid_ds" . 140.It Bq Er ENOENT 141No semaphore set was found corresponding to 142.Fa key , 143and IPC_CREAT was not specified. 144.El 145.Sh SEE ALSO 146.Xr semctl 2 , 147.Xr semop 2 , 148.Xr ftok 3 149