aboutsummaryrefslogtreecommitdiff
path: root/lib/libc/sys/shmget.2
blob: bf0bb588f612988cc55f0ca44f89f36f098fb09e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
.\"
.\" Copyright (c) 1995 David Hovemeyer <daveho@infocom.com>
.\"
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.\" $FreeBSD$
.\"
.Dd July 3, 1995
.Dt SHMGET 2
.Os
.Sh NAME
.Nm shmget
.Nd obtain a shared memory identifier
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
.Fd #include <machine/param.h>
.Fd #include <sys/types.h>
.Fd #include <sys/ipc.h>
.Fd #include <sys/shm.h>
.Ft int
.Fn shmget "key_t key" "int size" "int flag"
.Sh DESCRIPTION
Based on the values of
.Fa key
and
.Fa flag ,
.Fn shmget
returns the identifier of a newly created or previously existing shared
memory segment.
.\"
.\" The following bit about keys and modes also applies to semaphores
.\" and message queues.
.\"
The key
is analogous to a filename: it provides a handle that names an
IPC object.  There are three ways to specify a key:
.Bl -bullet
.It
IPC_PRIVATE may be specified, in which case a new IPC object
will be created.
.It
An integer constant may be specified.  If no IPC object corresponding
to
.Fa key
is specified and the IPC_CREAT bit is set in
.Fa flag ,
a new one will be created.
.It
.Fn ftok
may be used to generate a key from a pathname.  See
.Xr ftok 3 .
.El
.Pp
The mode of a newly created IPC object is determined by
.Em OR Ns 'ing
the following constants into the
.Fa flag
parameter:
.Bl -tag -width XSHM_WXX6XXX
.It Dv SHM_R
Read access for user.
.It Dv SHM_W
Write access for user.
.It Dv ( SHM_R>>3 )
Read access for group.
.It Dv ( SHM_W>>3 )
Write access for group.
.It Dv ( SHM_R>>6 )
Read access for other.
.It Dv ( SHM_W>>6 )
Write access for other.
.El
.\"
.\" XXX - we should also mention how uid, euid, and gid affect ownership
.\"	  and use
.\"
.\" end section about keys and modes
.\"
.Pp
When creating a new shared memory segment,
.Fa size
indicates the desired size of the new segment in bytes.  The size
of the segment may be rounded up to a multiple convenient to the
kernel (i.e., the page size).
.Sh RETURN VALUES
Upon successful completion,
.Fn shmget
returns the positive integer identifier of a shared memory segment.
Otherwise, -1 is returned and
.Va errno
set to indicate the error.
.Sh ERRORS
.Fn Shmget
will fail if:
.Bl -tag -width Er
.\"
.\" XXX What about ipcperm failing?
.\"
.It Bq Er EINVAL
Size specified is greater than the size of the previously existing segment.
Size specified is less than the system imposed minimum, or greater than
the system imposed maximum.
.It Bq Er ENOENT
No shared memory segment was found matching
.Fa key ,
and IPC_CREAT was not specified.
.It Bq Er ENOSPC
The kernel was unable to allocate enough memory to
satisfy the request.
.It Bq Er EEXIST
IPC_CREAT and IPC_EXCL were specified, and a shared memory segment
corresponding to
.Fa key
already exists.
.El
.Sh "SEE ALSO" 
.Xr shmat 2 ,
.Xr shmctl 2 ,
.Xr shmdt 2 ,
.Xr ftok 3