1SHMOP(2)                      System Calls Manual                     SHMOP(2)
2
3
4

NAME

6       shmat, shmdt - System V shared memory operations
7

LIBRARY

9       Standard C library (libc, -lc)
10

SYNOPSIS

12       #include <sys/shm.h>
13
14       void *shmat(int shmid, const void *_Nullable shmaddr, int shmflg);
15       int shmdt(const void *shmaddr);
16

DESCRIPTION

18   shmat()
19       shmat() attaches the System V shared memory segment identified by shmid
20       to the address space of the calling process.  The attaching address  is
21       specified by shmaddr with one of the following criteria:
22
23       •  If  shmaddr  is  NULL,  the system chooses a suitable (unused) page-
24          aligned address to attach the segment.
25
26       •  If shmaddr isn't NULL and SHM_RND is specified in shmflg, the attach
27          occurs  at  the address equal to shmaddr rounded down to the nearest
28          multiple of SHMLBA.
29
30       •  Otherwise, shmaddr must be a page-aligned address at which  the  at‐
31          tach occurs.
32
33       In  addition  to  SHM_RND,  the following flags may be specified in the
34       shmflg bit-mask argument:
35
36       SHM_EXEC (Linux-specific; since Linux 2.6.9)
37              Allow the contents of the segment to be  executed.   The  caller
38              must have execute permission on the segment.
39
40       SHM_RDONLY
41              Attach  the segment for read-only access.  The process must have
42              read permission for the segment.  If this flag is not specified,
43              the  segment  is  attached  for  read  and write access, and the
44              process must have read and write  permission  for  the  segment.
45              There is no notion of a write-only shared memory segment.
46
47       SHM_REMAP (Linux-specific)
48              This  flag  specifies that the mapping of the segment should re‐
49              place any existing mapping in the range starting at shmaddr  and
50              continuing  for  the  size of the segment.  (Normally, an EINVAL
51              error would result if a mapping already exists in  this  address
52              range.)  In this case, shmaddr must not be NULL.
53
54       The  brk(2)  value of the calling process is not altered by the attach.
55       The segment will automatically be detached at process exit.   The  same
56       segment  may  be  attached  as a read and as a read-write one, and more
57       than once, in the process's address space.
58
59       A successful shmat() call updates the members of the shmid_ds structure
60       (see shmctl(2)) associated with the shared memory segment as follows:
61
62shm_atime is set to the current time.
63
64shm_lpid is set to the process-ID of the calling process.
65
66shm_nattch is incremented by one.
67
68   shmdt()
69       shmdt() detaches the shared memory segment located at the address spec‐
70       ified by shmaddr from the address space of the  calling  process.   The
71       to-be-detached segment must be currently attached with shmaddr equal to
72       the value returned by the attaching shmat() call.
73
74       On a successful shmdt() call, the system updates