Penguin
Annotated edit history of shmctl(2) version 1, including all changes. View license author blame.
Rev Author # Line
1 perry 1 SHMCTL
2 !!!SHMCTL
3 NAME
4 SYNOPSIS
5 DESCRIPTION
6 SYSTEM CALLS
7 RETURN VALUE
8 ERRORS
9 NOTE
10 CONFORMING TO
11 SEE ALSO
12 ----
13 !!NAME
14
15
16 shmctl - shared memory control
17 !!SYNOPSIS
18
19
20 __#include __
21
22
23 __#include __
24
25
26 __int shmctl(int__ ''shmid''__, int__
27 ''cmd''__, struct shmid_ds
28 *__''buf''__);__
29 !!DESCRIPTION
30
31
32 __shmctl()__ allows the user to receive information on a
33 shared memory segment, set the owner, group, and permissions
34 of a shared memory segment, or destroy a segment. The
35 information about the segment identified by ''shmid'' is
36 returned in a ''shmid_ds'' structure:
37
38
39 struct shmid_ds {
40 struct ipc_perm shm_perm; /* operation perms */
41 int shm_segsz; /* size of segment (bytes) */
42 time_t shm_atime; /* last attach time */
43 time_t shm_dtime; /* last detach time */
44 time_t shm_ctime; /* last change time */
45 unsigned short shm_cpid; /* pid of creator */
46 unsigned short shm_lpid; /* pid of last operator */
47 short shm_nattch; /* no. of current attaches */
48 /* the following are private */
49 unsigned short shm_npages; /* size of segment (pages) */
50 unsigned long *shm_pages;
51 struct shm_desc *attaches; /* descriptors for attaches */
52 };
53
54
55 The fields in the member ''shm_perm'' can be
56 set:
57
58
59 struct ipc_perm
60 {
61 key_t key;
62 __ ushort uid__; /* __owner__ euid and egid */
63 __ ushort gid__;
64 ushort cuid; /* creator euid and egid */
65 ushort cgid;
66 __ ushort mode__; /* lower 9 bits of access modes */
67 ushort seq; /* sequence number */
68 };
69
70
71 The following ''cmds'' are available:
72
73
74 __IPC_STAT__
75
76
77 is used to copy the information about the shared memory
78 segment into the buffer ''buf''. The user must have
79 __read__ access to the shared memory
80 segment.
81
82
83 __IPC_SET__
84
85
86 is used to apply the changes the user has made to the
87 ''uid'', ''gid'', or ''mode'' members of the
88 ''shm_perms'' field. Only the lowest 9 bits of
89 ''mode'' are used. The ''shm_ctime'' member is also
90 updated. The user must be the owner, creator, or the
91 super-user.
92
93
94 __IPC_RMID__
95
96
97 is used to mark the segment as destroyed. It will actually
98 be destroyed after the last detach. (I.e., when the
99 ''shm_nattch'' member of the associated structure
100 ''shmid_ds'' is zero.) The user must be the owner,
101 creator, or the super-user.
102
103
104 The user ''must'' ensure that a segment is eventually
105 destroyed; otherwise its pages that were faulted in will
106 remain in memory or swap.
107
108
109 In addition, the __super-user__ can prevent or allow
110 swapping of a shared memory segment with the following
111 ''cmds'': (Linux only)
112
113
114 __SHM_LOCK__
115
116
117 prevents swapping of a shared memory segment. The user must
118 fault in any pages that are required to be present after
119 locking is enabled.
120
121
122 __SHM_UNLOCK__
123
124
125 allows the shared memory segment to be swapped
126 out.
127
128
129 The __IPC_INFO__, __SHM_STAT__ and __SHM_INFO__
130 control calls are used by the ipcs(8) program to
131 provide information on allocated resources. In the future,
132 these man be modified as needed or moved to a proc file
133 system interface.
134 !!SYSTEM CALLS
135
136
137 __fork()__
138
139
140 After a __fork()__ the child inherits the attached shared
141 memory segments.
142
143
144 __exec()__
145
146
147 After an __exec()__ all attached shared memory segments
148 are detached (not destroyed).
149
150
151 __exit()__
152
153
154 Upon __exit()__ all attached shared memory segments are
155 detached (not destroyed).
156 !!RETURN VALUE
157
158
159 0 is returned on success, -1 on error.
160 !!ERRORS
161
162
163 On error, __errno__ will be set to one of the
164 following:
165
166
167 __EACCES__
168
169
170 is returned if __IPC_STAT__ is requested and
171 ''shm_perm.modes'' does not allow read access for
172 ''msqid''.
173
174
175 __EFAULT__
176
177
178 The argument ''cmd'' has value __IPC_SET__ or
179 __IPC_STAT__ but the address pointed to by ''buf''
180 isn't accessible.
181
182
183 __EINVAL__
184
185
186 is returned if ''shmid'' is not a valid identifier, or
187 ''cmd'' is not a valid command.
188
189
190 __EIDRM__
191
192
193 is returned if ''shmid'' points to a removed
194 identifier.
195
196
197 __EPERM__
198
199
200 is returned if __IPC_SET__ or __IPC_RMID__ is
201 attempted, and the user is not the creator, the owner, or
202 the super-user, and the user does not have permission
203 granted to their group or to the world.
204 !!NOTE
205
206
207 Various fields in a ''struct shmid_ds'' were shorts under
208 Linux 2.2 and have become longs under Linux 2.4. To take
209 advantage of this, a recompilation under glibc-2.1.91 or
210 later should suffice. (The kernel distinguishes old and new
211 calls by a IPC_64 flag in ''cmd''.)
212 !!CONFORMING TO
213
214
215 SVr4, SVID. SVr4 documents additional error conditions
216 EINVAL, ENOENT, ENOSPC, ENOMEM, EEXIST. Neither SVr4 nor
217 SVID documents an EIDRM error condition.
218 !!SEE ALSO
219
220
221 shmget(2), shmop(2)
222 ----
This page is a man page (or other imported legacy content). We are unable to automatically determine the license status of this page.