1SVIPC(7) Linux Programmer's Manual SVIPC(7)
2
3
4
6 svipc - System V interprocess communication mechanisms
7
9 # include <sys/types.h>
10 # include <sys/ipc.h>
11 # include <sys/msg.h>
12 # include <sys/sem.h>
13 # include <sys/shm.h>
14
16 This manual page refers to the Linux implementation of the System V
17 interprocess communication mechanisms: message queues, semaphore sets,
18 and shared memory segments. In the following, the word resource means
19 an instantiation of one among such mechanisms.
20
21 Resource Access Permissions
22 For each resource, the system uses a common structure of type struct
23 ipc_perm to store information needed in determining permissions to per‐
24 form an ipc operation. The ipc_perm structure, defined by the
25 <sys/ipc.h> system header file, includes the following members:
26
27 uid_t cuid; /* creator user ID */
28 gid_t cgid; /* creator group ID */
29 uid_t uid; /* owner user ID */
30 gid_t gid; /* owner group ID */
31 ushort mode; /* r/w permissions */
32
33 The mode member of the ipc_perm structure defines, with its lower 9
34 bits, the access permissions to the resource for a process executing an
35 ipc system call. The permissions are interpreted as follows:
36
37 0400 Read by user.
38 0200 Write by user.
39 0040 Read by group.
40 0020 Write by group.
41 0004 Read by others.
42 0002 Write by others.
43
44 Bits 0100, 0010, and 0001 (the execute bits) are unused by the system.
45 Furthermore, "write" effectively means "alter" for a semaphore set.
46
47 The same system header file also defines the following symbolic con‐
48 stants:
49
50 IPC_CREAT Create entry if key doesn't exist.
51
52 IPC_EXCL Fail if key exists.
53
54 IPC_NOWAIT Error if request must wait.
55
56 IPC_PRIVATE Private key.
57
58 IPC_RMID Remove resource.
59
60 IPC_SET Set resource options.
61
62 IPC_STAT Get resource options.
63
64 Note that IPC_PRIVATE is a key_t type, while all the other symbolic
65 constants are flag fields and can be OR'ed into an int type variable.
66
67 Message Queues
68 A message queue is uniquely identified by a positive integer (its
69 msqid) and has an associated data structure of type struct msqid_ds,
70 defined in <sys/msg.h>, containing the following members:
71
72 struct ipc_perm msg_perm;
73 msgqnum_t msg_qnum; /* no of messages on queue */
74 msglen_t msg_qbytes; /* bytes max on a queue */
75 pid_t msg_lspid; /* PID of last msgsnd() call */
76 pid_t msg_lrpid; /* PID of last msgrcv() call */
77 time_t msg_stime; /* last msgsnd() time */
78 time_t msg_rtime; /* last msgrcv() time */
79 time_t msg_ctime; /* last change time */
80
81 msg_perm ipc_perm structure that specifies the access permissions on
82 the message queue.
83
84 msg_qnum Number of messages currently on the message queue.
85
86 msg_qbytes Maximum number of bytes of message text allowed on the mes‐
87 sage queue.
88
89 msg_lspid ID of the process that performed the last msgsnd() system
90 call.
91
92 msg_lrpid ID of the process that performed the last msgrcv() system
93 call.
94
95 msg_stime Time of the last msgsnd() system call.
96
97 msg_rtime Time of the last msgcv() system call.
98
99 msg_ctime Time of the last system call that changed a member of the
100 msqid_ds structure.
101
102 Semaphore Sets
103 A semaphore set is uniquely identified by a positive integer (its
104 semid) and has an associated data structure of type struct semid_ds,
105 defined in <sys/sem.h>, containing the following members:
106
107 struct ipc_perm sem_perm;
108 time_t sem_otime; /* last operation time */
109 time_t sem_ctime; /* last change time */
110 ulong sem_nsems; /* count of sems in set */
111
112 sem_perm ipc_perm structure that specifies the access permissions on
113 the semaphore set.
114
115 sem_otime Time of last semop() system call.
116
117 sem_ctime Time of last semctl() system call that changed a member of
118 the above structure or of one semaphore belonging to the
119 set.
120
121 sem_nsems Number of semaphores in the set. Each semaphore of the set
122 is referenced by a non-negative integer ranging from 0 to
123 sem_nsems-1.
124
125 A semaphore is a data structure of type struct sem containing the fol‐
126 lowing members:
127
128 int semval; /* semaphore value */
129 int sempid; /* PID for last operation */
130
131 semval Semaphore value: a non-negative integer.
132
133 sempid ID of the last process that performed a semaphore operation
134 on this semaphore.
135
136 Shared Memory Segments
137 A shared memory segment is uniquely identified by a positive integer
138 (its shmid) and has an associated data structure of type struct
139 shmid_ds, defined in <sys/shm.h>, containing the following members:
140
141 struct ipc_perm shm_perm;
142 size_t shm_segsz; /* size of segment */
143 pid_t shm_cpid; /* PID of creator */
144 pid_t shm_lpid; /* PID, last operation */
145 shmatt_t shm_nattch; /* no. of current attaches */
146 time_t shm_atime; /* time of last attach */
147 time_t shm_dtime; /* time of last detach */
148 time_t shm_ctime; /* time of last change */
149
150 shm_perm ipc_perm structure that specifies the access permissions on
151 the shared memory segment.
152
153 shm_segsz Size in bytes of the shared memory segment.
154
155 shm_cpid ID of the process that created the shared memory segment.
156
157 shm_lpid ID of the last process that executed a shmat() or shmdt()
158 system call.
159
160 shm_nattch Number of current alive attaches for this shared memory seg‐
161 ment.
162
163 shm_atime Time of the last shmat() system call.
164
165 shm_dtime Time of the last shmdt() system call.
166
167 shm_ctime Time of the last shmctl() system call that changed shmid_ds.
168
170 msgctl(2), msgget(2), msgrcv(2), msgsnd(2), semctl(2), semget(2),
171 semop(2), shmat(2), shmctl(2), shmdt(2), shmget(2), ftok(3)
172
173
174
175Linux 0.99.13 1993-11-01 SVIPC(7)