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
19

DESCRIPTION

21       The shmat() function operates on XSI shared memory (see the Base  Defi‐
22       nitions  volume  of  IEEE Std 1003.1-2001, Section 3.340, Shared Memory
23       Object). It is unspecified whether this function interoperates with the
24       realtime interprocess communication facilities defined in 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 seg‐
45          ment 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.
52
53       Otherwise,  the  shared  memory  segment shall not be attached, shmat()
54       shall return -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  XSI
60              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
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  XSI Interprocess Communication can be easily modified to
86       use the alternative interfaces.
87

RATIONALE

89       None.
90

FUTURE DIRECTIONS

92       None.
93

SEE ALSO

95       XSI Interprocess Communication, Realtime, exec() , exit(), fork(), shm‐
96       ctl(),  shmdt(),  shmget(),  shm_open(), shm_unlink(), the Base Defini‐
97       tions volume of IEEE Std 1003.1-2001, <sys/shm.h>
98
100       Portions of this text are reprinted and reproduced in  electronic  form
101       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
102       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
103       Specifications  Issue  6,  Copyright  (C) 2001-2003 by the Institute of
104       Electrical and Electronics Engineers, Inc and The Open  Group.  In  the
105       event of any discrepancy between this version and the original IEEE and
106       The Open Group Standard, the original IEEE and The Open Group  Standard
107       is  the  referee document. The original Standard can be obtained online
108       at http://www.opengroup.org/unix/online.html .
109
110
111
112IEEE/The Open Group                  2003                            SHMAT(3P)
Impressum