1SHMGET(3P)                 POSIX Programmer's Manual                SHMGET(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       shmget — get an XSI shared memory segment
14

SYNOPSIS

16       #include <sys/shm.h>
17
18       int shmget(key_t key, size_t size, int shmflg);
19

DESCRIPTION

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

RETURN VALUE

60       Upon successful completion, shmget() shall return a non-negative  inte‐
61       ger,  namely  a shared memory identifier; otherwise, it shall return −1
62       and set errno to indicate the error.
63

ERRORS

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

EXAMPLES

96       None.
97

APPLICATION USAGE

99       The POSIX Realtime Extension defines alternative interfaces for  inter‐
100       process  communication.  Application  developers  who  need  to use IPC
101       should design their applications so that modules using the IPC routines
102       described  in Section 2.7, XSI Interprocess Communication can be easily
103       modified to use the alternative interfaces.
104

RATIONALE

106       None.
107

FUTURE DIRECTIONS

109       None.
110

SEE ALSO

112       Section 2.7, XSI Interprocess  Communication,  Section  2.8,  Realtime,
113       ftok(), shmat(), shmctl(), shmdt(), shm_open(), shm_unlink()
114
115       The Base Definitions volume of POSIX.1‐2008, Section 3.342, Shared Mem‐
116       ory Object, <sys_shm.h>
117
119       Portions of this text are reprinted and reproduced in  electronic  form
120       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
121       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
122       Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
123       cal and Electronics Engineers,  Inc  and  The  Open  Group.   (This  is
124       POSIX.1-2008  with  the  2013  Technical Corrigendum 1 applied.) In the
125       event of any discrepancy between this version and the original IEEE and
126       The  Open Group Standard, the original IEEE and The Open Group Standard
127       is the referee document. The original Standard can be  obtained  online
128       at http://www.unix.org/online.html .
129
130       Any  typographical  or  formatting  errors that appear in this page are
131       most likely to have been introduced during the conversion of the source
132       files  to  man page format. To report such errors, see https://www.ker
133       nel.org/doc/man-pages/reporting_bugs.html .
134
135
136
137IEEE/The Open Group                  2013                           SHMGET(3P)
Impressum