1.\" $OpenBSD: shmget.2,v 1.16 2008/04/05 14:56:39 jmc Exp $ 2.\" $NetBSD: shmget.2,v 1.2 1997/03/27 08:20:39 mikel Exp $ 3.\" 4.\" Copyright (c) 1995 Frank van der Linden 5.\" All rights reserved. 6.\" 7.\" Redistribution and use in source and binary forms, with or without 8.\" modification, are permitted provided that the following conditions 9.\" are met: 10.\" 1. Redistributions of source code must retain the above copyright 11.\" notice, this list of conditions and the following disclaimer. 12.\" 2. Redistributions in binary form must reproduce the above copyright 13.\" notice, this list of conditions and the following disclaimer in the 14.\" documentation and/or other materials provided with the distribution. 15.\" 3. All advertising materials mentioning features or use of this software 16.\" must display the following acknowledgement: 17.\" This product includes software developed for the NetBSD Project 18.\" by Frank van der Linden 19.\" 4. The name of the author may not be used to endorse or promote products 20.\" derived from this software without specific prior written permission 21.\" 22.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 23.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 24.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 25.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 26.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 31.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32.\"/ 33.Dd $Mdocdate: April 5 2008 $ 34.Dt SHMGET 2 35.Os 36.Sh NAME 37.Nm shmget 38.Nd get shared memory area identifier 39.Sh SYNOPSIS 40.Fd #include <sys/types.h> 41.Fd #include <sys/ipc.h> 42.Fd #include <sys/shm.h> 43.Ft int 44.Fn shmget "key_t key" "size_t size" "int shmflg" 45.Sh DESCRIPTION 46.Fn shmget 47returns the shared memory identifier associated with the key 48.Fa key . 49.Pp 50A shared memory segment is created if either 51.Fa key 52is equal to 53.Dv IPC_PRIVATE , 54or 55.Fa key 56does not have a shared memory segment identifier associated with it, and the 57.Dv IPC_CREAT 58bit is set in 59.Fa shmflg . 60.Pp 61If a new shared memory segment is created, the data structure associated with 62it (the 63.Va shmid_ds 64structure, see 65.Xr shmctl 2 ) 66is initialized as follows: 67.Bl -bullet 68.It 69.Va shm_perm.cuid 70and 71.Va shm_perm.uid 72are set to the effective uid of the calling process. 73.It 74.Va shm_perm.gid 75and 76.Va shm_perm.cgid 77are set to the effective gid of the calling process. 78.It 79.Va shm_perm.mode 80is set to the lower 9 bits of 81.Fa shmflg . 82.It 83.Va shm_lpid , 84.Va shm_nattch , 85.Va shm_atime , 86and 87.Va shm_dtime 88are set to 0. 89.It 90.Va shm_ctime 91is set to the current time. 92.It 93.Va shm_segsz 94is set to the value of 95.Fa size . 96.El 97.Sh RETURN VALUES 98Upon successful completion a positive shared memory segment identifier is 99returned. 100Otherwise, \-1 is returned and the global variable 101.Va errno 102is set to indicate the error. 103.Sh ERRORS 104.Bl -tag -width Er 105.It Bq Er EACCES 106A shared memory segment is already associated with 107.Fa key 108and the caller has no permission to access it. 109.It Bq Er EEXIST 110Both 111.Dv IPC_CREAT 112and 113.Dv IPC_EXCL 114are set in 115.Fa shmflg , 116and a shared memory segment is already associated with 117.Fa key . 118.It Bq Er EINVAL 119A shared memory segment is already associated with 120.Fa key 121and its 122.Fa size 123is less than the requested size. 124.It Bq Er ENOSPC 125A new shared memory identifier could not be created because the system limit 126for the number of shared memory identifiers has been reached. 127.It Bq Er ENOENT 128.Dv IPC_CREAT 129was not set in 130.Fa shmflg 131and no shared memory segment associated with 132.Fa key 133was found. 134.It Bq Er ENOMEM 135There is not enough memory left to create a shared memory segment of the 136requested size. 137.El 138.Sh SEE ALSO 139.Xr ipcrm 1 , 140.Xr ipcs 1 , 141.Xr mmap 2 , 142.Xr shmat 2 , 143.Xr shmctl 2 , 144.Xr ftok 3 145