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

NAME

6       shmat - XSI shared memory attach operation
7

SYNOPSIS

9       #include <sys/shm.h>
10
11       void *shmat(int shmid, const void *shmaddr, int shmflg);
12
13

DESCRIPTION

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

RETURN VALUE

42       Upon  successful  completion,  shmat()  shall  increment  the  value of
43       shm_nattch in the data structure associated with the shared  memory  ID
44       of  the  attached  shared memory segment and return the segment's start
45       address.
46
47       Otherwise, the shared memory segment shall  not  be  attached,  shmat()
48       shall return -1, and errno shall be set to indicate the error.
49

ERRORS

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

EXAMPLES

73       None.
74

APPLICATION USAGE

76       The  POSIX Realtime Extension defines alternative interfaces for inter‐
77       process communication. Application  developers  who  need  to  use  IPC
78       should design their applications so that modules using the IPC routines
79       described in XSI Interprocess Communication can be easily  modified  to
80       use the alternative interfaces.
81

RATIONALE

83       None.
84

FUTURE DIRECTIONS

86       None.
87

SEE ALSO

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