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: src/lib/libc/sys/shmget.2,v 1.8.2.6 2001/12/14 18:34:01 ru Exp $ 27.\" 28.Dd January 4, 2014 29.Dt SHMGET 2 30.Os 31.Sh NAME 32.Nm shmget 33.Nd obtain a shared memory identifier 34.Sh LIBRARY 35.Lb libc 36.Sh SYNOPSIS 37.In machine/param.h 38.In sys/types.h 39.In sys/ipc.h 40.In sys/shm.h 41.Ft int 42.Fn shmget "key_t key" "size_t size" "int flag" 43.Sh DESCRIPTION 44Based on the values of 45.Fa key 46and 47.Fa flag , 48.Fn shmget 49returns the identifier of a newly created or previously existing shared 50memory segment. 51.\" 52.\" The following bit about keys and modes also applies to semaphores 53.\" and message queues. 54.\" 55The key 56is analogous to a filename: it provides a handle that names an 57IPC object. 58There are three ways to specify a key: 59.Bl -bullet 60.It 61.Dv IPC_PRIVATE 62may be specified, in which case a new IPC object will be created. 63.It 64An integer constant may be specified. 65If no IPC object corresponding to 66.Fa key 67is specified and the 68.Dv IPC_CREAT 69bit is set in 70.Fa flag , 71a new one will be created. 72.It 73.Fn ftok 74may be used to generate a key from a pathname. 75See 76.Xr ftok 3 . 77.El 78.Pp 79The mode of a newly created IPC object is determined by 80.Em OR Ns 'ing 81the following constants into the 82.Fa flag 83parameter: 84.Bl -tag -width XSHM_WXX6XXX 85.It Dv SHM_R 86Read access for user. 87.It Dv SHM_W 88Write access for user. 89.It Dv ( SHM_R>>3 ) 90Read access for group. 91.It Dv ( SHM_W>>3 ) 92Write access for group. 93.It Dv ( SHM_R>>6 ) 94Read access for other. 95.It Dv ( SHM_W>>6 ) 96Write access for other. 97.El 98.\" 99.\" XXX - we should also mention how uid, euid, and gid affect ownership 100.\" and use 101.\" 102.\" end section about keys and modes 103.\" 104.Pp 105When creating a new shared memory segment, 106.Fa size 107indicates the desired size of the new segment in bytes. 108The size of the segment may be rounded up to a multiple convenient to the 109kernel (i.e., the page size). 110.Sh RETURN VALUES 111Upon successful completion, 112.Fn shmget 113returns the positive integer identifier of a shared memory segment. 114Otherwise, -1 is returned and 115.Va errno 116set to indicate the error. 117.Sh ENVIRONMENT 118The XSI Interprocess Communication family of functions is also available 119as an implementation in userspace. 120To use it, the 121.Xr sysvipcd 8 122daemon has to be running. 123.Pp 124If the 125.Ev USR_SYSVIPC 126variable is set in a process' environment, the process and its children 127will use the userspace implementation. 128.Sh ERRORS 129.Fn Shmget 130will fail if: 131.Bl -tag -width Er 132.\" 133.\" XXX What about ipcperm failing? 134.\" 135.It Bq Er EINVAL 136Size specified is greater than the size of the previously existing segment. 137Size specified is less than the system imposed minimum, or greater than 138the system imposed maximum. 139.It Bq Er ENOENT 140No shared memory segment was found matching 141.Fa key , 142and 143.Dv IPC_CREAT 144was not specified. 145.It Bq Er ENOSPC 146The kernel was unable to allocate enough memory to 147satisfy the request. 148.It Bq Er EEXIST 149.Dv IPC_CREAT 150and 151.Dv IPC_EXCL 152were specified, and a shared memory segment corresponding to 153.Fa key 154already exists. 155.El 156.Sh "SEE ALSO" 157.Xr shmat 2 , 158.Xr shmctl 2 , 159.Xr shmdt 2 , 160.Xr ftok 3 161.Sh AUTHORS 162.An -nosplit 163The 164.Dx 165specific userspace implementation (see 166.Sx ENVIRONMENT ) 167was written by 168.An Larisa Grigore . 169