1.\" 2.\" Copyright (c) 1995 David Hovemeyer <[email protected]> 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 July 3, 1995 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 61IPC_PRIVATE may be specified, in which case a new IPC object 62will be created. 63.It 64An integer constant may be specified. 65If no IPC object corresponding 66to 67.Fa key 68is specified and the IPC_CREAT bit is set in 69.Fa flag , 70a new one will be created. 71.It 72The 73.Xr ftok 3 74may be used to generate a key from a pathname. 75.El 76.Pp 77The mode of a newly created IPC object is determined by 78.Em OR Ns 'ing 79the following constants into the 80.Fa flag 81argument: 82.Bl -tag -width XSHM_WXX6XXX 83.It Dv SHM_R 84Read access for user. 85.It Dv SHM_W 86Write access for user. 87.It Dv ( SHM_R>>3 ) 88Read access for group. 89.It Dv ( SHM_W>>3 ) 90Write access for group. 91.It Dv ( SHM_R>>6 ) 92Read access for other. 93.It Dv ( SHM_W>>6 ) 94Write access for other. 95.El 96.\" 97.\" XXX - we should also mention how uid, euid, and gid affect ownership 98.\" and use 99.\" 100.\" end section about keys and modes 101.\" 102.Pp 103When creating a new shared memory segment, 104.Fa size 105indicates the desired size of the new segment in bytes. 106The size 107of the segment may be rounded up to a multiple convenient to the 108kernel (i.e., the page size). 109.Sh RETURN VALUES 110Upon successful completion, 111.Fn shmget 112returns the positive integer identifier of a shared memory segment. 113Otherwise, -1 is returned and 114.Va errno 115set to indicate the error. 116.Sh ERRORS 117The 118.Fn shmget 119system call 120will fail if: 121.Bl -tag -width Er 122.\" 123.\" XXX What about ipcperm failing? 124.\" 125.It Bq Er EINVAL 126Size specified is greater than the size of the previously existing segment. 127Size specified is less than the system imposed minimum, or greater than 128the system imposed maximum. 129.It Bq Er ENOENT 130No shared memory segment was found matching 131.Fa key , 132and IPC_CREAT was not specified. 133.It Bq Er ENOSPC 134The kernel was unable to allocate enough memory to 135satisfy the request. 136.It Bq Er EEXIST 137IPC_CREAT and IPC_EXCL were specified, and a shared memory segment 138corresponding to 139.Fa key 140already exists. 141.El 142.Sh "SEE ALSO" 143.Xr shmat 2 , 144.Xr shmctl 2 , 145.Xr shmdt 2 , 146.Xr ftok 3 147