xref: /dragonfly/lib/libc/sys/shmget.2 (revision d4ef6694)
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.  There are three ways to specify a key:
58.Bl -bullet
59.It
60IPC_PRIVATE may be specified, in which case a new IPC object
61will be created.
62.It
63An integer constant may be specified.  If no IPC object corresponding
64to
65.Fa key
66is specified and the IPC_CREAT bit is set in
67.Fa flag ,
68a new one will be created.
69.It
70.Fn ftok
71may be used to generate a key from a pathname.  See
72.Xr ftok 3 .
73.El
74.Pp
75The mode of a newly created IPC object is determined by
76.Em OR Ns 'ing
77the following constants into the
78.Fa flag
79parameter:
80.Bl -tag -width XSHM_WXX6XXX
81.It Dv SHM_R
82Read access for user.
83.It Dv SHM_W
84Write access for user.
85.It Dv ( SHM_R>>3 )
86Read access for group.
87.It Dv ( SHM_W>>3 )
88Write access for group.
89.It Dv ( SHM_R>>6 )
90Read access for other.
91.It Dv ( SHM_W>>6 )
92Write access for other.
93.El
94.\"
95.\" XXX - we should also mention how uid, euid, and gid affect ownership
96.\"	  and use
97.\"
98.\" end section about keys and modes
99.\"
100.Pp
101When creating a new shared memory segment,
102.Fa size
103indicates the desired size of the new segment in bytes.  The size
104of the segment may be rounded up to a multiple convenient to the
105kernel (i.e., the page size).
106.Sh RETURN VALUES
107Upon successful completion,
108.Fn shmget
109returns the positive integer identifier of a shared memory segment.
110Otherwise, -1 is returned and
111.Va errno
112set to indicate the error.
113.Sh ENVIRONMENT
114The XSI Interprocess Communication family of functions is also available
115as an implementation in userspace.
116To use it, the
117.Xr sysvipcd 8
118daemon has to be running.
119.Pp
120If the
121.Ev USR_SYSVIPC
122variable is set in a process' environment, the process and its children
123will use the userspace implementation.
124.Sh ERRORS
125.Fn Shmget
126will fail if:
127.Bl -tag -width Er
128.\"
129.\" XXX What about ipcperm failing?
130.\"
131.It Bq Er EINVAL
132Size specified is greater than the size of the previously existing segment.
133Size specified is less than the system imposed minimum, or greater than
134the system imposed maximum.
135.It Bq Er ENOENT
136No shared memory segment was found matching
137.Fa key ,
138and IPC_CREAT was not specified.
139.It Bq Er ENOSPC
140The kernel was unable to allocate enough memory to
141satisfy the request.
142.It Bq Er EEXIST
143IPC_CREAT and IPC_EXCL were specified, and a shared memory segment
144corresponding to
145.Fa key
146already exists.
147.El
148.Sh "SEE ALSO"
149.Xr shmat 2 ,
150.Xr shmctl 2 ,
151.Xr shmdt 2 ,
152.Xr ftok 3
153.Sh AUTHORS
154.An -nosplit
155The
156.Dx
157specific userspace implementation (see
158.Sx ENVIRONMENT )
159was written by
160.An Larisa Grigore .
161