1SEMGET(3P)                 POSIX Programmer's Manual                SEMGET(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       semget — get set of XSI semaphores
13

SYNOPSIS

15       #include <sys/sem.h>
16
17       int semget(key_t key, int nsems, int semflg);
18

DESCRIPTION

20       The semget() function operates on XSI semaphores (see the Base  Defini‐
21       tions volume of POSIX.1‐2017, Section 4.17, Semaphore).  It is unspeci‐
22       fied whether this function interoperates with the realtime interprocess
23       communication facilities defined in Section 2.8, Realtime.
24
25       The  semget() function shall return the semaphore identifier associated
26       with key.
27
28       A semaphore identifier with its associated semid_ds data structure  and
29       its associated set of nsems semaphores (see <sys/sem.h>) is created for
30       key if one of the following is true:
31
32        *  The argument key is equal to IPC_PRIVATE.
33
34        *  The argument key does not already have a semaphore identifier asso‐
35           ciated with it and (semflg &IPC_CREAT) is non-zero.
36
37       Upon creation, the semid_ds data structure associated with the new sem‐
38       aphore identifier is initialized as follows:
39
40        *  In the operation permissions structure sem_perm.cuid, sem_perm.uid,
41           sem_perm.cgid,  and sem_perm.gid shall be set to the effective user
42           ID and effective group ID, respectively, of the calling process.
43
44        *  The low-order 9 bits of sem_perm.mode shall be set to the low-order
45           9 bits of semflg.
46
47        *  The variable sem_nsems shall be set to the value of nsems.
48
49        *  The variable sem_otime shall be set to 0 and sem_ctime shall be set
50           to the current time, as described in  Section  2.7.1,  IPC  General
51           Description.
52
53        *  The  data  structure associated with each semaphore in the set need
54           not be initialized. The semctl() function with the  command  SETVAL
55           or SETALL can be used to initialize each semaphore.
56

RETURN VALUE

58       Upon  successful completion, semget() shall return a non-negative inte‐
59       ger, namely a semaphore identifier; otherwise, it shall return  -1  and
60       set errno to indicate the error.
61

ERRORS

63       The semget() function shall fail if:
64
65       EACCES A  semaphore identifier exists for key, but operation permission
66              as specified by the low-order 9 bits  of  semflg  would  not  be
67              granted; see Section 2.7, XSI Interprocess Communication.
68
69       EEXIST A  semaphore identifier exists for the argument key but ((semflg
70              &IPC_CREAT) &&(semflg &IPC_EXCL)) is non-zero.
71
72       EINVAL The value of nsems is either less than or equal to 0 or  greater
73              than  the system-imposed limit, or a semaphore identifier exists
74              for the argument key, but the number of semaphores  in  the  set
75              associated  with it is less than nsems and nsems is not equal to
76              0.
77
78       ENOENT A semaphore identifier does not exist for the argument  key  and
79              (semflg &IPC_CREAT) is equal to 0.
80
81       ENOSPC A  semaphore  identifier is to be created but the system-imposed
82              limit on the maximum number of  allowed  semaphores  system-wide
83              would be exceeded.
84
85       The following sections are informative.
86

EXAMPLES

88       Refer to semop().
89

APPLICATION USAGE

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

RATIONALE

98       None.
99

FUTURE DIRECTIONS

101       A future version may require that the value of the semval, sempid, sem‐
102       ncnt, and semzcnt members of all semaphores in a semaphore set be  ini‐
103       tialized  to zero when a call to semget() creates a semaphore set. Many
104       semaphore implementations already do this  and  it  greatly  simplifies
105       what an application must do to initialize a semaphore set.
106

SEE ALSO

108       Section  2.7,  XSI  Interprocess  Communication, Section 2.8, Realtime,
109       ftok(), semctl(), semop(), sem_close(), sem_destroy(),  sem_getvalue(),
110       sem_init(), sem_open(), sem_post(), sem_trywait(), sem_unlink()
111
112       The  Base  Definitions volume of POSIX.1‐2017, Section 4.17, Semaphore,
113       <sys_sem.h>
114
116       Portions of this text are reprinted and reproduced in  electronic  form
117       from  IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
118       table Operating System Interface (POSIX), The Open Group Base  Specifi‐
119       cations  Issue  7, 2018 Edition, Copyright (C) 2018 by the Institute of
120       Electrical and Electronics Engineers, Inc and The Open Group.   In  the
121       event of any discrepancy between this version and the original IEEE and
122       The Open Group Standard, the original IEEE and The Open Group  Standard
123       is  the  referee document. The original Standard can be obtained online
124       at http://www.opengroup.org/unix/online.html .
125
126       Any typographical or formatting errors that appear  in  this  page  are
127       most likely to have been introduced during the conversion of the source
128       files to man page format. To report such errors,  see  https://www.ker
129       nel.org/doc/man-pages/reporting_bugs.html .
130
131
132
133IEEE/The Open Group                  2017                           SEMGET(3P)
Impressum