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.Dd March 4, 2018 27.Dt SHMGET 2 28.Os 29.Sh NAME 30.Nm shmget 31.Nd obtain a shared memory identifier 32.Sh LIBRARY 33.Lb libc 34.Sh SYNOPSIS 35.In sys/shm.h 36.Ft int 37.Fn shmget "key_t key" "size_t size" "int flag" 38.Sh DESCRIPTION 39Based on the values of 40.Fa key 41and 42.Fa flag , 43.Fn shmget 44returns the identifier of a newly created or previously existing shared 45memory segment. 46.\" 47.\" The following bit about keys and modes also applies to semaphores 48.\" and message queues. 49.\" 50The key 51is analogous to a filename: it provides a handle that names an 52IPC object. 53There are three ways to specify a key: 54.Bl -bullet 55.It 56IPC_PRIVATE may be specified, in which case a new IPC object 57will be created. 58.It 59An integer constant may be specified. 60If no IPC object corresponding 61to 62.Fa key 63is specified and the IPC_CREAT bit is set in 64.Fa flag , 65a new one will be created. 66.It 67The 68.Xr ftok 3 69may be used to generate a key from a pathname. 70.El 71.Pp 72The mode of a newly created IPC object is determined by 73which are set by ORing these constants into the 74.Fa flag 75argument: 76.Bl -tag -width 0000 77.It Dv 0400 78Read access for owner. 79.It Dv 0200 80Write access for owner. 81.It Dv 0040 82Read access for group. 83.It Dv 0020 84Write access for group. 85.It Dv 0004 86Read access for other. 87.It Dv 0002 88Write access for other. 89.El 90.\" 91.\" XXX - we should also mention how uid, euid, and gid affect ownership 92.\" and use 93.\" 94.\" end section about keys and modes 95.\" 96.Pp 97When creating a new shared memory segment, 98.Fa size 99indicates the desired size of the new segment in bytes. 100The size 101of the segment may be rounded up to a multiple convenient to the 102kernel (i.e., the page size). 103.Sh RETURN VALUES 104Upon successful completion, 105.Fn shmget 106returns the positive integer identifier of a shared memory segment. 107Otherwise, -1 is returned and 108.Va errno 109set to indicate the error. 110.Sh ERRORS 111The 112.Fn shmget 113system call 114will fail if: 115.Bl -tag -width Er 116.\" 117.\" XXX What about ipcperm failing? 118.\" 119.It Bq Er EINVAL 120Size specified is greater than the size of the previously existing segment. 121Size specified is less than the system imposed minimum, or greater than 122the system imposed maximum. 123.It Bq Er ENOENT 124No shared memory segment was found matching 125.Fa key , 126and IPC_CREAT was not specified. 127.It Bq Er ENOSPC 128The kernel was unable to allocate enough memory to 129satisfy the request. 130.It Bq Er EEXIST 131IPC_CREAT and IPC_EXCL were specified, and a shared memory segment 132corresponding to 133.Fa key 134already exists. 135.El 136.Sh "SEE ALSO" 137.Xr shmat 2 , 138.Xr shmctl 2 , 139.Xr shmdt 2 , 140.Xr ftok 3 141