1SHMAT(3P)                  POSIX Programmer's Manual                 SHMAT(3P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10

NAME

12       shmat — XSI shared memory attach operation
13

SYNOPSIS

15       #include <sys/shm.h>
16
17       void *shmat(int shmid, const void *shmaddr, int shmflg);
18

DESCRIPTION

20       The shmat() function operates on XSI shared memory (see the Base  Defi‐
21       nitions  volume  of POSIX.1‐2017, Section 3.346, Shared Memory Object).
22       It is unspecified whether this function interoperates with the realtime
23       interprocess communication facilities defined in Section 2.8, Realtime.
24
25       The shmat() function attaches the shared memory segment associated with
26       the shared memory identifier specified by shmid to the address space of
27       the  calling  process. The segment is attached at the address specified
28       by one of the following criteria:
29
30        *  If shmaddr is a null pointer, the segment is attached at the  first
31           available address as selected by the system.
32
33        *  If shmaddr is not a null pointer and (shmflg &SHM_RND) is non-zero,
34           the  segment  is  attached  at  the  address  given   by   (shmaddr
35           -((uintptr_t)shmaddr %SHMLBA)). The character '%' is the C-language
36           remainder operator.
37
38        *  If shmaddr is not a null pointer and (shmflg &SHM_RND)  is  0,  the
39           segment is attached at the address given by shmaddr.
40
41        *  The segment is attached for reading if (shmflg &SHM_RDONLY) is non-
42           zero and the calling process has read permission; otherwise, if  it
43           is  0  and  the  calling process has read and write permission, the
44           segment is attached for reading and writing.
45

RETURN VALUE

47       Upon successful  completion,  shmat()  shall  increment  the  value  of
48       shm_nattch  in  the data structure associated with the shared memory ID
49       of the attached shared memory segment and return  the  segment's  start
50       address.   Also,  the  shm_atime  timestamp shall be set to the current
51       time, as described in Section 2.7.1, IPC General Description.
52
53       Otherwise, the shared memory segment shall  not  be  attached,  shmat()
54       shall return (void *)-1, and errno shall be set to indicate the error.
55

ERRORS

57       The shmat() function shall fail if:
58
59       EACCES Operation  permission is denied to the calling process; see Sec‐
60              tion 2.7, XSI Interprocess Communication.
61
62       EINVAL The value of shmid is not a valid shared memory identifier,  the
63              shmaddr  is  not  a  null  pointer,  and  the  value of (shmaddr
64              -((uintptr_t)shmaddr %SHMLBA)) is an illegal address for attach‐
65              ing shared memory; or the shmaddr is not a null pointer, (shmflg
66              &SHM_RND) is 0, and the value of shmaddr is an  illegal  address
67              for attaching shared memory.
68
69       EMFILE The  number  of  shared  memory segments attached to the calling
70              process would exceed the system-imposed limit.
71
72       ENOMEM The available data space is not large enough to accommodate  the
73              shared memory segment.
74
75       The following sections are informative.
76

EXAMPLES

78       None.
79

APPLICATION USAGE

81       The  POSIX Realtime Extension defines alternative interfaces for inter‐
82       process communication. Application  developers  who  need  to  use  IPC
83       should design their applications so that modules using the IPC routines
84       described in Section 2.7, XSI Interprocess Communication can be  easily
85       modified to use the alternative interfaces.
86

RATIONALE

88       None.
89

FUTURE DIRECTIONS

91       None.
92

SEE ALSO

94       Section  2.7,  XSI  Interprocess  Communication, Section 2.8, Realtime,
95       exec,  exit(),  fork(),  shmctl(),   shmdt(),   shmget(),   shm_open(),
96       shm_unlink()
97
98       The Base Definitions volume of POSIX.1‐2017, Section 3.346, Shared Mem‐
99       ory Object, <sys_shm.h>
100
102       Portions of this text are reprinted and reproduced in  electronic  form
103       from  IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
104       table Operating System Interface (POSIX), The Open Group Base  Specifi‐
105       cations  Issue  7, 2018 Edition, Copyright (C) 2018 by the Institute of
106       Electrical and Electronics Engineers, Inc and The Open Group.   In  the
107       event of any discrepancy between this version and the original IEEE and
108       The Open Group Standard, the original IEEE and The Open Group  Standard
109       is  the  referee document. The original Standard can be obtained online
110       at http://www.opengroup.org/unix/online.html .
111
112       Any typographical or formatting errors that appear  in  this  page  are
113       most likely to have been introduced during the conversion of the source
114       files to man page format. To report such errors,  see  https://www.ker
115       nel.org/doc/man-pages/reporting_bugs.html .
116
117
118
119IEEE/The Open Group                  2017                            SHMAT(3P)
Impressum