]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - lib/libc/sys/shmget.2
MFC r330409:
[FreeBSD/stable/10.git] / lib / libc / sys / shmget.2
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$
27 .\"
28 .Dd March 4, 2018
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 sys/shm.h
38 .Ft int
39 .Fn shmget "key_t key" "size_t size" "int flag"
40 .Sh DESCRIPTION
41 Based on the values of
42 .Fa key
43 and
44 .Fa flag ,
45 .Fn shmget
46 returns the identifier of a newly created or previously existing shared
47 memory segment.
48 .\"
49 .\" The following bit about keys and modes also applies to semaphores
50 .\" and message queues.
51 .\"
52 The key
53 is analogous to a filename: it provides a handle that names an
54 IPC object.
55 There are three ways to specify a key:
56 .Bl -bullet
57 .It
58 IPC_PRIVATE may be specified, in which case a new IPC object
59 will be created.
60 .It
61 An integer constant may be specified.
62 If no IPC object corresponding
63 to
64 .Fa key
65 is specified and the IPC_CREAT bit is set in
66 .Fa flag ,
67 a new one will be created.
68 .It
69 The
70 .Xr ftok 3
71 may be used to generate a key from a pathname.
72 .El
73 .Pp
74 The mode of a newly created IPC object is determined by
75 which are set by ORing these constants into the
76 .Fa flag
77 argument:
78 .Bl -tag -width 0000
79 .It Dv 0400
80 Read access for owner.
81 .It Dv 0200
82 Write access for owner.
83 .It Dv 0040
84 Read access for group.
85 .It Dv 0020
86 Write access for group.
87 .It Dv 0004
88 Read access for other.
89 .It Dv 0002
90 Write access for other.
91 .El
92 .\"
93 .\" XXX - we should also mention how uid, euid, and gid affect ownership
94 .\"       and use
95 .\"
96 .\" end section about keys and modes
97 .\"
98 .Pp
99 When creating a new shared memory segment,
100 .Fa size
101 indicates the desired size of the new segment in bytes.
102 The size
103 of the segment may be rounded up to a multiple convenient to the
104 kernel (i.e., the page size).
105 .Sh RETURN VALUES
106 Upon successful completion,
107 .Fn shmget
108 returns the positive integer identifier of a shared memory segment.
109 Otherwise, -1 is returned and
110 .Va errno
111 set to indicate the error.
112 .Sh ERRORS
113 The
114 .Fn shmget
115 system call
116 will fail if:
117 .Bl -tag -width Er
118 .\"
119 .\" XXX What about ipcperm failing?
120 .\"
121 .It Bq Er EINVAL
122 Size specified is greater than the size of the previously existing segment.
123 Size specified is less than the system imposed minimum, or greater than
124 the system imposed maximum.
125 .It Bq Er ENOENT
126 No shared memory segment was found matching
127 .Fa key ,
128 and IPC_CREAT was not specified.
129 .It Bq Er ENOSPC
130 The kernel was unable to allocate enough memory to
131 satisfy the request.
132 .It Bq Er EEXIST
133 IPC_CREAT and IPC_EXCL were specified, and a shared memory segment
134 corresponding to
135 .Fa key
136 already exists.
137 .El
138 .Sh "SEE ALSO"
139 .Xr shmat 2 ,
140 .Xr shmctl 2 ,
141 .Xr shmdt 2 ,
142 .Xr ftok 3