Imported upstream version 1.5
[manpages-zh.git] / raw / man5 / ipc.5
blobd3c32115a086a9b9d6b048317c81a450e277fe61
1 .\" Copyright 1993 Giorgio Ciucci (giorgio@crcc.it)
2 .\"
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
6 .\"
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one
11 .\" 
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein.  The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
18 .\" professionally.
19 .\" 
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
22 .\"
23 .TH IPC 5 1993-11-01 "Linux 0.99.13" "Linux Programmer's Manual" 
24 .SH NAME
25 ipc \- System V interprocess communication mechanisms
26 .SH SYNOPSIS
27 .nf
29 # include <sys/types.h>
31 # include <sys/ipc.h>
33 # include <sys/msg.h>
35 # include <sys/sem.h>
37 # include <sys/shm.h>
38 .SH DESCRIPTION
39 This manual page refers to the Linux implementation of the System V
40 interprocess communication mechanisms:
41 message queues, semaphore sets, and shared memory segments.
42 In the following, the word
43 .B resource
44 means an instantiation of one among such mechanisms.
45 .SS Resource Access Permissions
46 For each resource, the system uses a common structure of type
47 .BR "struct ipc_perm"
48 to store information needed in determining permissions to perform an
49 ipc operation.
50 The
51 .B ipc_perm
52 structure, defined by the
53 .I <sys/ipc.h>
54 system header file, includes the following members:
55 .sp
57         ushort cuid;     
58 /* creator user id */
59 .br
61         ushort cgid;     
62 /* creator group id */
63 .br
65         ushort uid;      
66 /* owner user id */
67 .br
69         ushort gid;     
70 /* owner group id */
71 .br
73         ushort mode;    
74 /* r/w permissions */
75 .PP
76 The
77 .B mode
78 member of the
79 .B ipc_perm
80 structure defines, with its lower 9 bits, the access permissions to the
81 resource for a process executing an ipc system call.
82 The permissions are interpreted as follows:
83 .sp
84 .nf
85         0400    Read by user.
86         0200    Write by user.
87 .sp .5
88         0040    Read by group.
89         0020    Write by group.
90 .sp .5
91         0004    Read by others.
92         0002    Write by others.
93 .fi
94 .PP
95 Bits 0100, 0010, and 0001 (the execute bits) are unused by the system.
96 Furthermore,
97 "write"
98 effectively means
99 "alter"
100 for a semaphore set.
102 The same system header file also defines the following symbolic
103 constants:
104 .TP 14
105 .B IPC_CREAT
106 Create entry if key doesn't exist.
108 .B IPC_EXCL
109 Fail if key exists.
111 .B IPC_NOWAIT
112 Error if request must wait.
114 .B IPC_PRIVATE
115 Private key.
117 .B IPC_RMID
118 Remove resource.
120 .B IPC_SET
121 Set resource options.
123 .B IPC_STAT
124 Get resource options.
126 Note that
127 .B IPC_PRIVATE
128 is a
129 .B key_t
130 type, while all the other symbolic constants are flag fields and can
131 be OR'ed into an
132 .B int
133 type variable.
134 .SS Message Queues
135 A message queue is uniquely identified by a positive integer
136 .RI "(its " msqid )
137 and has an associated data structure of type
138 .BR "struct msquid_ds" ,
139 defined in
140 .IR <sys/msg.h> ,
141 containing the following members:
144         struct ipc_perm msg_perm;
147         ushort msg_qnum;        
148 /* no of messages on queue */
151         ushort msg_qbytes;      
152 /* bytes max on a queue */
155         ushort msg_lspid;       
156 /* pid of last msgsnd call */
159         ushort msg_lrpid;       
160 /* pid of last msgrcv call */
163         time_t msg_stime;       
164 /* last msgsnd time */
167         time_t msg_rtime;       
168 /* last msgrcv time */
171         time_t msg_ctime;       
172 /* last change time */
173 .TP 11
174 .B msg_perm
175 .B ipc_perm
176 structure that specifies the access permissions on the message
177 queue.
179 .B msg_qnum
180 Number of messages currently on the message queue.
182 .B msg_qbytes
183 Maximum number of bytes of message text allowed on the message
184 queue.
186 .B msg_lspid
187 ID of the process that performed the last
188 .B msgsnd
189 system call.
191 .B msg_lrpid
192 ID of the process that performed the last
193 .B msgrcv
194 system call.
196 .B msg_stime
197 Time of the last
198 .B msgsnd
199 system call.
201 .B msg_rtime
202 Time of the last
203 .B msgcv
204 system call.
206 .B msg_ctime
207 Time of the last
208 system call that changed a member of the
209 .B msqid_ds
210 structure.
211 .SS Semaphore Sets
212 A semaphore set is uniquely identified by a positive integer
213 .RI "(its " semid )
214 and has an associated data structure of type
215 .BR "struct semid_ds" ,
216 defined in
217 .IR <sys/sem.h> ,
218 containing the following members:
221         struct ipc_perm sem_perm;
224         time_t sem_otime;       
225 /* last operation time */
228         time_t sem_ctime;       
229 /* last change time */
232         ushort sem_nsems;       
233 /* count of sems in set */
234 .TP 11
235 .B sem_perm
236 .B ipc_perm
237 structure that specifies the access permissions on the semaphore
238 set.
240 .B sem_otime
241 Time of last
242 .B semop
243 system call.
245 .B sem_ctime
246 Time of last
247 .B semctl
248 system call that changed a member of the above structure or of one
249 semaphore belonging to the set.
251 .B sem_nsems
252 Number of semaphores in the set.
253 Each semaphore of the set is referenced by a non-negative integer
254 ranging from
255 .B 0
257 .BR sem_nsems\-1 .
259 A semaphore is a data structure of type
260 .B "struct sem"
261 containing the following members:
264         ushort semval;  
265 /* semaphore value */
268         short sempid;   
269 /* pid for last operation */
272         ushort semncnt;
273 /* nr awaiting semval to increase */
276         ushort semzcnt;
277 /* nr awaiting semval = 0 */
278 .TP 11
279 .B semval
280 Semaphore value: a non-negative integer.
282 .B sempid
283 ID of the last process that performed a semaphore operation
284 on this semaphore.
286 .B semncnt
287 Number of processes suspended awaiting for
288 .B semval
289 to increase.
291 .B semznt
292 Number of processes suspended awaiting for
293 .B semval
294 to become zero.
295 .SS Shared Memory Segments
296 A shared memory segment is uniquely identified by a positive integer
297 .RI "(its " shmid )
298 and has an associated data structure of type
299 .BR "struct shmid_ds" ,
300 defined in
301 .IR <sys/shm.h> ,
302 containing the following members:
305         struct ipc_perm shm_perm;
308         int shm_segsz;  
309 /* size of segment */
312         ushort shm_cpid;        
313 /* pid of creator */
316         ushort shm_lpid;        
317 /* pid, last operation */
320         short shm_nattch;       
321 /* no. of current attaches */
324         time_t shm_atime;       
325 /* time of last attach */
328         time_t shm_dtime;       
329 /* time of last detach */
332         time_t shm_ctime;       
333 /* time of last change */
334 .TP 11
335 .B shm_perm
336 .B ipc_perm
337 structure that specifies the access permissions on the shared memory
338 segment.
340 .B shm_segsz
341 Size in bytes of the shared memory segment.
343 .B shm_cpid
344 ID of the process that created the shared memory segment.
346 .B shm_lpid
347 ID of the last process that executed a
348 .B shmat
350 .B shmdt
351 system call.
353 .B shm_nattch
354 Number of current alive attaches for this shared memory segment.
356 .B shm_atime
357 Time of the last
358 .B shmat
359 system call.
361 .B shm_dtime
362 Time of the last
363 .B shmdt
364 system call.
366 .B shm_ctime
367 Time of the last
368 .B shmctl
369 system call that changed
370 .BR shmid_ds .
371 .SH "SEE ALSO"
372 .BR ftok (3),
373 .BR msgctl (2),
374 .BR msgget (2),
375 .BR msgrcv (2),
376 .BR msgsnd (2),
377 .BR semctl (2),
378 .BR semget (2),
379 .BR semop (2),
380 .BR shmat (2),
381 .BR shmctl (2),
382 .BR shmget (2),
383 .BR shmdt (2)