2 .\" Copyright (C) 2006 Michael Kerrisk <mtk.manpages@gmail.com>
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .TH sem_open 3 (date) "Linux man-pages (unreleased)"
8 sem_open \- initialize and open a named semaphore
11 .RI ( libpthread ", " \-lpthread )
14 .BR "#include <fcntl.h>" " /* For O_* constants */"
15 .BR "#include <sys/stat.h>" " /* For mode constants */"
16 .B #include <semaphore.h>
18 .BI "sem_t *sem_open(const char *" name ", int " oflag );
19 .BI "sem_t *sem_open(const char *" name ", int " oflag ,
20 .BI " mode_t " mode ", unsigned int " value );
24 creates a new POSIX semaphore or opens an existing semaphore.
25 The semaphore is identified by
27 For details of the construction of
34 argument specifies flags that control the operation of the call.
35 (Definitions of the flags values can be obtained by including
41 then the semaphore is created if
42 it does not already exist.
43 The owner (user ID) of the semaphore is set to the effective
44 user ID of the calling process.
45 The group ownership (group ID) is set to the effective group ID
46 of the calling process.
47 .\" In reality the filesystem IDs are used on Linux.
54 then an error is returned if a semaphore with the given
62 then two additional arguments must be supplied.
65 argument specifies the permissions to be placed on the new semaphore,
68 (Symbolic definitions for the permissions bits can be obtained by including
70 The permissions settings are masked against the process umask.
71 Both read and write permission should be granted to each class of
72 user that will access the semaphore.
75 argument specifies the initial value for the new semaphore.
78 is specified, and a semaphore with the given
88 returns the address of the new semaphore;
89 this address is used when calling other semaphore-related functions.
96 set to indicate the error.
100 The semaphore exists, but the caller does not have permission to
110 but a semaphore with this
121 consists of just "/", followed by no other characters.
124 The per-process limit on the number of open file descriptors has been reached.
131 The system-wide limit on the total number of open files has been reached.
136 flag was not specified in
138 and no semaphore with this
142 .\" this error can occur if we have a name of the (nonportable) form
143 .\" /dir/name, and the directory /dev/shm/dir does not exist.
152 For an explanation of the terms used in this section, see
160 Interface Attribute Value
163 T} Thread safety MT-Safe
169 POSIX.1-2001, POSIX.1-2008.
172 .BR sem_getvalue (3),