xref: /netbsd/lib/libc/sys/shmget.2 (revision bf9ec67e)
1.\"	$NetBSD: shmget.2,v 1.14 2002/02/08 01:28:22 ross Exp $
2.\"
3.\" Copyright (c) 1995 Frank van der Linden
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.\" 3. All advertising materials mentioning features or use of this software
15.\"    must display the following acknowledgement:
16.\"      This product includes software developed for the NetBSD Project
17.\"      by Frank van der Linden
18.\" 4. The name of the author may not be used to endorse or promote products
19.\"    derived from this software without specific prior written permission
20.\"
21.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31.\"
32.Dd August 25, 1999
33.Dt SHMGET 2
34.Os
35.Sh NAME
36.Nm shmget
37.Nd get shared memory segment
38.Sh LIBRARY
39.Lb libc
40.Sh SYNOPSIS
41.Fd #include \*[Lt]sys/shm.h\*[Gt]
42.Ft int
43.Fn shmget "key_t key" "size_t size" "int shmflg"
44.Sh DESCRIPTION
45.Fn shmget
46returns the shared memory identifier associated with the key
47.Fa key .
48The
49.Fa shmflg
50should be a combination of the following flags:
51.Bl -tag -offset indent -width IPC_NOWAIT
52.It Dv IPC_CREAT
53create if segment does not exist
54.It Dv IPC_EXCL
55fail if segment already exists
56.It Dv IPC_NOWAIT
57return error instead of waiting
58.El
59.Pp
60and nine bits of access bits, based on:
61.Bl -tag -offset indent -width IPC_R
62.It Dv IPC_R
63read permission
64.It Dv IPC_W
65write permission
66.It Dv IPC_M
67changing control info permission
68.El
69.Pp
70A shared memory segment is created if either
71.Fa key
72is equal to
73.Dv IPC_PRIVATE ,
74or
75.Fa key
76does not have a shared memory segment identifier associated with it, and the
77.Dv IPC_CREAT
78bit is set in
79.Fa shmflg .
80.Pp
81If a new shared memory segment is created, the data structure
82associated with it (the
83.Va shmid_ds
84structure, see
85.Xr shmctl 2 )
86is initialized as follows:
87.Bl -bullet
88.It
89.Va shm_perm.cuid
90and
91.Va shm_perm.uid
92are set to the effective uid of the calling process.
93.It
94.Va shm_perm.gid
95and
96.Va shm_perm.cgid
97are set to the effective gid of the calling process.
98.It
99.Va shm_perm.mode
100is set to the lower 9 bits of
101.Fa shmflg .
102.It
103.Va shm_lpid ,
104.Va shm_nattch ,
105.Va shm_atime ,
106and
107.Va shm_dtime
108are set to 0.
109.It
110.Va shm_ctime
111is set to the current time.
112.It
113.Va shm_segsz
114is set to the value of
115.Fa size .
116.El
117.Sh RETURN VALUES
118Upon successful completion a positive shared memory segment identifier
119is returned.
120Otherwise, -1 is returned and the global variable
121.Va errno
122is set to indicate the error.
123.Sh ERRORS
124.Bl -tag -width Er
125.It Bq Er EACCES
126A shared memory segment is already associated with
127.Fa key
128and the caller has no permission to access it.
129.It Bq Er EEXIST
130Both
131.Dv IPC_CREAT
132and
133.Dv IPC_EXCL
134are set in
135.Fa shmflg ,
136and a shared memory segment is already associated with
137.Fa key .
138.It Bq Er ENOSPC
139A new shared memory identifier could not be created because the system limit
140for the number of shared memory identifiers has been reached.
141.It Bq Er ENOENT
142.Dv IPC_CREAT
143is not set in
144.Fa shmflg
145and no shared memory segment associated with
146.Fa key
147was found.
148.It Bq Er ENOMEM
149There is not enough memory left to create a shared memory segment of the
150requested size.
151.El
152.Sh SEE ALSO
153.Xr mmap 2 ,
154.Xr shmat 2 ,
155.Xr shmctl 2 ,
156.Xr ftok 3
157.Sh STANDARDS
158The
159.Nm
160system call conforms to
161.St -xsh5 .
162.Sh HISTORY
163Shared memory segments appeared in the first release of
164.At V .
165