1*8269e767SBrooks Davis.\" 2*8269e767SBrooks Davis.\" Copyright (c) 1995 David Hovemeyer <daveho@infocom.com> 3*8269e767SBrooks Davis.\" 4*8269e767SBrooks Davis.\" All rights reserved. 5*8269e767SBrooks Davis.\" 6*8269e767SBrooks Davis.\" Redistribution and use in source and binary forms, with or without 7*8269e767SBrooks Davis.\" modification, are permitted provided that the following conditions 8*8269e767SBrooks Davis.\" are met: 9*8269e767SBrooks Davis.\" 1. Redistributions of source code must retain the above copyright 10*8269e767SBrooks Davis.\" notice, this list of conditions and the following disclaimer. 11*8269e767SBrooks Davis.\" 2. Redistributions in binary form must reproduce the above copyright 12*8269e767SBrooks Davis.\" notice, this list of conditions and the following disclaimer in the 13*8269e767SBrooks Davis.\" documentation and/or other materials provided with the distribution. 14*8269e767SBrooks Davis.\" 15*8269e767SBrooks Davis.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR 16*8269e767SBrooks Davis.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17*8269e767SBrooks Davis.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18*8269e767SBrooks Davis.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT, 19*8269e767SBrooks Davis.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20*8269e767SBrooks Davis.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21*8269e767SBrooks Davis.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22*8269e767SBrooks Davis.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23*8269e767SBrooks Davis.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24*8269e767SBrooks Davis.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25*8269e767SBrooks Davis.\" 26*8269e767SBrooks Davis.Dd March 4, 2018 27*8269e767SBrooks Davis.Dt SEMGET 2 28*8269e767SBrooks Davis.Os 29*8269e767SBrooks Davis.Sh NAME 30*8269e767SBrooks Davis.Nm semget 31*8269e767SBrooks Davis.Nd obtain a semaphore id 32*8269e767SBrooks Davis.Sh LIBRARY 33*8269e767SBrooks Davis.Lb libc 34*8269e767SBrooks Davis.Sh SYNOPSIS 35*8269e767SBrooks Davis.In sys/sem.h 36*8269e767SBrooks Davis.Ft int 37*8269e767SBrooks Davis.Fn semget "key_t key" "int nsems" "int flag" 38*8269e767SBrooks Davis.Sh DESCRIPTION 39*8269e767SBrooks DavisBased on the values of 40*8269e767SBrooks Davis.Fa key 41*8269e767SBrooks Davisand 42*8269e767SBrooks Davis.Fa flag , 43*8269e767SBrooks Davis.Fn semget 44*8269e767SBrooks Davisreturns the identifier of a newly created or previously existing 45*8269e767SBrooks Davisset of semaphores. 46*8269e767SBrooks Davis.\" 47*8269e767SBrooks Davis.\" This is copied verbatim from the shmget manpage. Perhaps 48*8269e767SBrooks Davis.\" it should go in a common manpage, such as .Xr ipc 2 49*8269e767SBrooks Davis.\" 50*8269e767SBrooks DavisThe key 51*8269e767SBrooks Davisis analogous to a filename: it provides a handle that names an 52*8269e767SBrooks DavisIPC object. 53*8269e767SBrooks DavisThere are three ways to specify a key: 54*8269e767SBrooks Davis.Bl -bullet 55*8269e767SBrooks Davis.It 56*8269e767SBrooks DavisIPC_PRIVATE may be specified, in which case a new IPC object 57*8269e767SBrooks Daviswill be created. 58*8269e767SBrooks Davis.It 59*8269e767SBrooks DavisAn integer constant may be specified. 60*8269e767SBrooks DavisIf no IPC object corresponding 61*8269e767SBrooks Davisto 62*8269e767SBrooks Davis.Fa key 63*8269e767SBrooks Davisis specified and the IPC_CREAT bit is set in 64*8269e767SBrooks Davis.Fa flag , 65*8269e767SBrooks Davisa new one will be created. 66*8269e767SBrooks Davis.It 67*8269e767SBrooks DavisThe 68*8269e767SBrooks Davis.Xr ftok 3 69*8269e767SBrooks Davisfunction 70*8269e767SBrooks Davismay be used to generate a key from a pathname. 71*8269e767SBrooks Davis.El 72*8269e767SBrooks Davis.\" 73*8269e767SBrooks Davis.\" Likewise for this section, except SHM_* becomes SEM_*. 74*8269e767SBrooks Davis.\" 75*8269e767SBrooks Davis.Pp 76*8269e767SBrooks DavisThe mode of a newly created IPC object is determined by ORing these constants 77*8269e767SBrooks Davisinto the 78*8269e767SBrooks Davis.Fa flag 79*8269e767SBrooks Davisargument: 80*8269e767SBrooks Davis.Bl -tag -width 0000 81*8269e767SBrooks Davis.It Dv 0400 82*8269e767SBrooks DavisRead access for user. 83*8269e767SBrooks Davis.It Dv 0200 84*8269e767SBrooks DavisAlter access for user. 85*8269e767SBrooks Davis.It Dv 0040 86*8269e767SBrooks DavisRead access for group. 87*8269e767SBrooks Davis.It Dv 0020 88*8269e767SBrooks DavisAlter access for group. 89*8269e767SBrooks Davis.It Dv 0004 90*8269e767SBrooks DavisRead access for other. 91*8269e767SBrooks Davis.It Dv 0002 92*8269e767SBrooks DavisAlter access for other. 93*8269e767SBrooks Davis.El 94*8269e767SBrooks Davis.Pp 95*8269e767SBrooks DavisIf a new set of semaphores is being created, 96*8269e767SBrooks Davis.Fa nsems 97*8269e767SBrooks Davisis used to indicate the number of semaphores the set should contain. 98*8269e767SBrooks DavisOtherwise, 99*8269e767SBrooks Davis.Fa nsems 100*8269e767SBrooks Davismay be specified as 0. 101*8269e767SBrooks Davis.Sh RETURN VALUES 102*8269e767SBrooks DavisThe 103*8269e767SBrooks Davis.Fn semget 104*8269e767SBrooks Davissystem call 105*8269e767SBrooks Davisreturns the id of a semaphore set if successful; otherwise, -1 106*8269e767SBrooks Davisis returned and 107*8269e767SBrooks Davis.Va errno 108*8269e767SBrooks Davisis set to indicate the error. 109*8269e767SBrooks Davis.Sh ERRORS 110*8269e767SBrooks DavisThe 111*8269e767SBrooks Davis.Fn semget 112*8269e767SBrooks Davissystem call 113*8269e767SBrooks Daviswill fail if: 114*8269e767SBrooks Davis.Bl -tag -width Er 115*8269e767SBrooks Davis.\" ipcperm could fail (we are opening to read and write, as it were) 116*8269e767SBrooks Davis.It Bq Er EACCES 117*8269e767SBrooks DavisAccess permission failure. 118*8269e767SBrooks Davis.\" 119*8269e767SBrooks Davis.\" sysv_sem.c is quite explicit about these, so I'm pretty sure 120*8269e767SBrooks Davis.\" this is accurate 121*8269e767SBrooks Davis.\" 122*8269e767SBrooks Davis.It Bq Er EEXIST 123*8269e767SBrooks DavisIPC_CREAT and IPC_EXCL were specified, and a semaphore set 124*8269e767SBrooks Daviscorresponding to 125*8269e767SBrooks Davis.Fa key 126*8269e767SBrooks Davisalready exists. 127*8269e767SBrooks Davis.It Bq Er EINVAL 128*8269e767SBrooks DavisThe number of semaphores requested exceeds the system imposed maximum 129*8269e767SBrooks Davisper set. 130*8269e767SBrooks Davis.It Bq Er EINVAL 131*8269e767SBrooks DavisA semaphore set corresponding to 132*8269e767SBrooks Davis.Fa key 133*8269e767SBrooks Davisalready exists and contains fewer semaphores than 134*8269e767SBrooks Davis.Fa nsems . 135*8269e767SBrooks Davis.It Bq Er EINVAL 136*8269e767SBrooks DavisA semaphore set corresponding to 137*8269e767SBrooks Davis.Fa key 138*8269e767SBrooks Davisdoes not exist and 139*8269e767SBrooks Davis.Fa nsems 140*8269e767SBrooks Davisis 0 or negative. 141*8269e767SBrooks Davis.It Bq Er ENOSPC 142*8269e767SBrooks DavisInsufficiently many semaphores are available. 143*8269e767SBrooks Davis.It Bq Er ENOSPC 144*8269e767SBrooks DavisThe kernel could not allocate a 145*8269e767SBrooks Davis.Fa "struct semid_ds" . 146*8269e767SBrooks Davis.It Bq Er ENOENT 147*8269e767SBrooks DavisNo semaphore set was found corresponding to 148*8269e767SBrooks Davis.Fa key , 149*8269e767SBrooks Davisand IPC_CREAT was not specified. 150*8269e767SBrooks Davis.El 151*8269e767SBrooks Davis.Sh SEE ALSO 152*8269e767SBrooks Davis.Xr semctl 2 , 153*8269e767SBrooks Davis.Xr semop 2 , 154*8269e767SBrooks Davis.Xr ftok 3 155