1SHMCTL(2) Linux Programmer's Manual SHMCTL(2)
2
3
4
6 shmctl - shared memory control
7
9 #include <sys/ipc.h>
10 #include <sys/shm.h>
11
12 int shmctl(int shmid, int cmd, struct shmid_ds *buf);
13
15 shmctl() performs the control operation specified by cmd on the shared
16 memory segment whose identifier is given in shmid.
17
18 The buf argument is a pointer to a shmid_ds structure, defined in
19 <sys/shm.h> as follows:
20
21 struct shmid_ds {
22 struct ipc_perm shm_perm; /* Ownership and permissions */
23 size_t shm_segsz; /* Size of segment (bytes) */
24 time_t shm_atime; /* Last attach time */
25 time_t shm_dtime; /* Last detach time */
26 time_t shm_ctime; /* Last change time */
27 pid_t shm_cpid; /* PID of creator */
28 pid_t shm_lpid; /* PID of last shmat(2)/shmdt(2) */
29 shmatt_t shm_nattch; /* No. of current attaches */
30 ...
31 };
32
33 The ipc_perm structure is defined in <sys/ipc.h> as follows (the high‐
34 lighted fields are settable using IPC_SET):
35
36 struct ipc_perm {
37 key_t __key; /* Key supplied to shmget(2) */
38 uid_t uid; /* Effective UID of owner */
39 gid_t gid; /* Effective GID of owner */
40 uid_t cuid; /* Effective UID of creator */
41 gid_t cgid; /* Effective GID of creator */
42 unsigned short mode; /* Permissions + SHM_DEST and
43 SHM_LOCKED flags */
44 unsigned short __seq; /* Sequence number */
45 };
46
47 Valid values for cmd are:
48
49 IPC_STAT Copy information from the kernel data structure associated
50 with shmid into the shmid_ds structure pointed to by buf.
51 The caller must have read permission on the shared memory
52 segment.
53
54 IPC_SET Write the values of some members of the shmid_ds structure
55 pointed to by buf to the kernel data structure associated
56 with this shared memory segment, updating also its shm_ctime
57 member. The following fields can be changed: shm_perm.uid,
58 shm_perm.gid, and (the least significant 9 bits of)
59 shm_perm.mode. The effective UID of the calling process must
60 match the owner (shm_perm.uid) or creator (shm_perm.cuid) of
61 the shared memory segment, or the caller must be privileged.
62
63 IPC_RMID Mark the segment to be destroyed. The segment will only
64 actually be destroyed after the last process detaches it
65 (i.e., when the shm_nattch member of the associated structure
66 shmid_ds is zero). The caller must be the owner or creator,
67 or be privileged. If a segment has been marked for destruc‐
68 tion, then the (non-standard) SHM_DEST flag of the
69 shm_perm.mode field in the associated data structure
70 retrieved by IPC_STAT will be set.
71
72 The caller must ensure that a segment is eventually destroyed; other‐
73 wise its pages that were fault