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