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