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