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
11

NAME

13       shmat — XSI shared memory attach operation
14

SYNOPSIS

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

DESCRIPTION

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

RETURN VALUE

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

ERRORS

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

EXAMPLES

79       None.
80

APPLICATION USAGE

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

RATIONALE

89       None.
90

FUTURE DIRECTIONS

92       None.
93

SEE ALSO

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