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

NAME

6       shmget - get an XSI shared memory segment
7

SYNOPSIS

9       #include <sys/shm.h>
10
11       int shmget(key_t key, size_t size, int shmflg);
12
13

DESCRIPTION

15       The shmget() 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 shmget() function shall return the shared memory identifier associ‐
21       ated with key.
22
23       A  shared memory identifier, associated data structure, and shared mem‐
24       ory segment of at least size bytes (see <sys/shm.h>)  are  created  for
25       key if one of the following is true:
26
27        * The argument key is equal to IPC_PRIVATE.
28
29        * The  argument  key  does not already have a shared memory identifier
30          associated with it and (shmflg &IPC_CREAT) is non-zero.
31
32       Upon creation, the data structure associated with the new shared memory
33       identifier shall be initialized as follows:
34
35        * The   values  of  shm_perm.cuid,  shm_perm.uid,  shm_perm.cgid,  and
36          shm_perm.gid are set equal to the effective user  ID  and  effective
37          group ID, respectively, of the calling process.
38
39        * The  low-order  nine bits of shm_perm.mode are set equal to the low-
40          order nine bits of shmflg.
41
42        * The value of shm_segsz is set equal to the value of size.
43
44        * The values of shm_lpid, shm_nattch, shm_atime, and shm_dtime are set
45          equal to 0.
46
47        * The value of shm_ctime is set equal to the current time.
48
49       When the shared memory segment is created, it shall be initialized with
50       all zero values.
51

RETURN VALUE

53       Upon successful completion, shmget() shall return a non-negative  inte‐
54       ger,  namely  a shared memory identifier; otherwise, it shall return -1
55       and set errno to indicate the error.
56

ERRORS

58       The shmget() function shall fail if:
59
60       EACCES A shared memory identifier exists for key but operation  permis‐
61              sion as specified by the low-order nine bits of shmflg would not
62              be granted; see XSI Interprocess Communication .
63
64       EEXIST A shared memory identifier exists for the argument key but (shm‐
65              flg &IPC_CREAT) &&(shmflg &IPC_EXCL) is non-zero.
66
67       EINVAL A  shared  memory segment is to be created and the value of size
68              is less than the system-imposed minimum or greater than the sys‐
69              tem-imposed maximum.
70
71       EINVAL No  shared  memory  segment is to be created and a shared memory
72              segment exists for key but the size of  the  segment  associated
73              with it is less than size and size is not 0.
74
75       ENOENT A  shared  memory identifier does not exist for the argument key
76              and (shmflg &IPC_CREAT) is 0.
77
78       ENOMEM A shared memory identifier and associated shared memory  segment
79              shall be created, but the amount of available physical memory is
80              not sufficient to fill the request.
81
82       ENOSPC A shared memory identifier is to be  created,  but  the  system-
83              imposed  limit  on  the  maximum number of allowed shared memory
84              identifiers system-wide would be exceeded.
85
86
87       The following sections are informative.
88

EXAMPLES

90       None.
91

APPLICATION USAGE

93       The POSIX Realtime Extension defines alternative interfaces for  inter‐
94       process  communication.  Application  developers  who  need  to use IPC
95       should design their applications so that modules using the IPC routines
96       described  in  XSI Interprocess Communication can be easily modified to
97       use the alternative interfaces.
98

RATIONALE

100       None.
101

FUTURE DIRECTIONS

103       None.
104

SEE ALSO

106       XSI Interprocess Communication  ,  Realtime  ,  shmat()  ,  shmctl()  ,
107       shmdt()  ,  shm_open()  , shm_unlink() , the Base Definitions volume of
108       IEEE Std 1003.1-2001, <sys/shm.h>
109
111       Portions of this text are reprinted and reproduced in  electronic  form
112       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
113       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
114       Specifications  Issue  6,  Copyright  (C) 2001-2003 by the Institute of
115       Electrical and Electronics Engineers, Inc and The Open  Group.  In  the
116       event of any discrepancy between this version and the original IEEE and
117       The Open Group Standard, the original IEEE and The Open Group  Standard
118       is  the  referee document. The original Standard can be obtained online
119       at http://www.opengroup.org/unix/online.html .
120
121
122
123IEEE/The Open Group                  2003                            SHMGET(P)
Impressum