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 SHMGET 2 28*8269e767SBrooks Davis.Os 29*8269e767SBrooks Davis.Sh NAME 30*8269e767SBrooks Davis.Nm shmget 31*8269e767SBrooks Davis.Nd obtain a shared memory identifier 32*8269e767SBrooks Davis.Sh LIBRARY 33*8269e767SBrooks Davis.Lb libc 34*8269e767SBrooks Davis.Sh SYNOPSIS 35*8269e767SBrooks Davis.In sys/shm.h 36*8269e767SBrooks Davis.Ft int 37*8269e767SBrooks Davis.Fn shmget "key_t key" "size_t size" "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 shmget 44*8269e767SBrooks Davisreturns the identifier of a newly created or previously existing shared 45*8269e767SBrooks Davismemory segment. 46*8269e767SBrooks Davis.\" 47*8269e767SBrooks Davis.\" The following bit about keys and modes also applies to semaphores 48*8269e767SBrooks Davis.\" and message queues. 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 Davismay be used to generate a key from a pathname. 70*8269e767SBrooks Davis.El 71*8269e767SBrooks Davis.Pp 72*8269e767SBrooks DavisThe mode of a newly created IPC object is determined by 73*8269e767SBrooks Daviswhich are set by ORing these constants into the 74*8269e767SBrooks Davis.Fa flag 75*8269e767SBrooks Davisargument: 76*8269e767SBrooks Davis.Bl -tag -width 0000 77*8269e767SBrooks Davis.It Dv 0400 78*8269e767SBrooks DavisRead access for owner. 79*8269e767SBrooks Davis.It Dv 0200 80*8269e767SBrooks DavisWrite access for owner. 81*8269e767SBrooks Davis.It Dv 0040 82*8269e767SBrooks DavisRead access for group. 83*8269e767SBrooks Davis.It Dv 0020 84*8269e767SBrooks DavisWrite access for group. 85*8269e767SBrooks Davis.It Dv 0004 86*8269e767SBrooks DavisRead access for other. 87*8269e767SBrooks Davis.It Dv 0002 88*8269e767SBrooks DavisWrite access for other. 89*8269e767SBrooks Davis.El 90*8269e767SBrooks Davis.\" 91*8269e767SBrooks Davis.\" XXX - we should also mention how uid, euid, and gid affect ownership 92*8269e767SBrooks Davis.\" and use 93*8269e767SBrooks Davis.\" 94*8269e767SBrooks Davis.\" end section about keys and modes 95*8269e767SBrooks Davis.\" 96*8269e767SBrooks Davis.Pp 97*8269e767SBrooks DavisWhen creating a new shared memory segment, 98*8269e767SBrooks Davis.Fa size 99*8269e767SBrooks Davisindicates the desired size of the new segment in bytes. 100*8269e767SBrooks DavisThe size 101*8269e767SBrooks Davisof the segment may be rounded up to a multiple convenient to the 102*8269e767SBrooks Daviskernel (i.e., the page size). 103*8269e767SBrooks Davis.Sh RETURN VALUES 104*8269e767SBrooks DavisUpon successful completion, 105*8269e767SBrooks Davis.Fn shmget 106*8269e767SBrooks Davisreturns the positive integer identifier of a shared memory segment. 107*8269e767SBrooks DavisOtherwise, -1 is returned and 108*8269e767SBrooks Davis.Va errno 109*8269e767SBrooks Davisset to indicate the error. 110*8269e767SBrooks Davis.Sh ERRORS 111*8269e767SBrooks DavisThe 112*8269e767SBrooks Davis.Fn shmget 113*8269e767SBrooks Davissystem call 114*8269e767SBrooks Daviswill fail if: 115*8269e767SBrooks Davis.Bl -tag -width Er 116*8269e767SBrooks Davis.\" 117*8269e767SBrooks Davis.\" XXX What about ipcperm failing? 118*8269e767SBrooks Davis.\" 119*8269e767SBrooks Davis.It Bq Er EINVAL 120*8269e767SBrooks DavisSize specified is greater than the size of the previously existing segment. 121*8269e767SBrooks DavisSize specified is less than the system imposed minimum, or greater than 122*8269e767SBrooks Davisthe system imposed maximum. 123*8269e767SBrooks Davis.It Bq Er ENOENT 124*8269e767SBrooks DavisNo shared memory segment was found matching 125*8269e767SBrooks Davis.Fa key , 126*8269e767SBrooks Davisand IPC_CREAT was not specified. 127*8269e767SBrooks Davis.It Bq Er ENOSPC 128*8269e767SBrooks DavisThe kernel was unable to allocate enough memory to 129*8269e767SBrooks Davissatisfy the request. 130*8269e767SBrooks Davis.It Bq Er EEXIST 131*8269e767SBrooks DavisIPC_CREAT and IPC_EXCL were specified, and a shared memory segment 132*8269e767SBrooks Daviscorresponding to 133*8269e767SBrooks Davis.Fa key 134*8269e767SBrooks Davisalready exists. 135*8269e767SBrooks Davis.El 136*8269e767SBrooks Davis.Sh "SEE ALSO" 137*8269e767SBrooks Davis.Xr shmat 2 , 138*8269e767SBrooks Davis.Xr shmctl 2 , 139*8269e767SBrooks Davis.Xr shmdt 2 , 140*8269e767SBrooks Davis.Xr ftok 3 141