1 .\" Copyright (C) 2006 Michael Kerrisk <mtk.manpages@gmail.com>
3 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
5 .TH SEM_OPEN 3 2021-03-22 "Linux man-pages (unreleased)"
7 sem_open \- initialize and open a named semaphore
10 .RI ( libpthread ", " \-lpthread )
13 .BR "#include <fcntl.h>" " /* For O_* constants */"
14 .BR "#include <sys/stat.h>" " /* For mode constants */"
15 .B #include <semaphore.h>
17 .BI "sem_t *sem_open(const char *" name ", int " oflag );
18 .BI "sem_t *sem_open(const char *" name ", int " oflag ,
19 .BI " mode_t " mode ", unsigned int " value );
23 creates a new POSIX semaphore or opens an existing semaphore.
24 The semaphore is identified by
26 For details of the construction of
33 argument specifies flags that control the operation of the call.
34 (Definitions of the flags values can be obtained by including
40 then the semaphore is created if
41 it does not already exist.
42 The owner (user ID) of the semaphore is set to the effective
43 user ID of the calling process.
44 The group ownership (group ID) is set to the effective group ID
45 of the calling process.
46 .\" In reality the filesystem IDs are used on Linux.
53 then an error is returned if a semaphore with the given
61 then two additional arguments must be supplied.
64 argument specifies the permissions to be placed on the new semaphore,
67 (Symbolic definitions for the permissions bits can be obtained by including
69 The permissions settings are masked against the process umask.
70 Both read and write permission should be granted to each class of
71 user that will access the semaphore.
74 argument specifies the initial value for the new semaphore.
77 is specified, and a semaphore with the given
87 returns the address of the new semaphore;
88 this address is used when calling other semaphore-related functions.
95 set to indicate the error.
99 The semaphore exists, but the caller does not have permission to
109 but a semaphore with this
120 consists of just "/", followed by no other characters.
123 The per-process limit on the number of open file descriptors has been reached.
130 The system-wide limit on the total number of open files has been reached.
135 flag was not specified in
137 and no semaphore with this
141 .\" this error can occur if we have a name of the (nonportable) form
142 .\" /dir/name, and the directory /dev/shm/dir does not exist.
151 For an explanation of the terms used in this section, see
159 Interface Attribute Value
162 T} Thread safety MT-Safe
168 POSIX.1-2001, POSIX.1-2008.
171 .BR sem_getvalue (3),