1 .\" Copyright (C) 2006 Michael Kerrisk <mtk.manpages@gmail.com>
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
25 .TH SEM_OPEN 3 2021-03-22 "Linux" "Linux Programmer's Manual"
27 sem_open \- initialize and open a named semaphore
30 .BR "#include <fcntl.h>" " /* For O_* constants */"
31 .BR "#include <sys/stat.h>" " /* For mode constants */"
32 .B #include <semaphore.h>
34 .BI "sem_t *sem_open(const char *" name ", int " oflag );
35 .BI "sem_t *sem_open(const char *" name ", int " oflag ,
36 .BI " mode_t " mode ", unsigned int " value );
39 Link with \fI\-pthread\fP.
42 creates a new POSIX semaphore or opens an existing semaphore.
43 The semaphore is identified by
45 For details of the construction of
52 argument specifies flags that control the operation of the call.
53 (Definitions of the flags values can be obtained by including
59 then the semaphore is created if
60 it does not already exist.
61 The owner (user ID) of the semaphore is set to the effective
62 user ID of the calling process.
63 The group ownership (group ID) is set to the effective group ID
64 of the calling process.
65 .\" In reality the filesystem IDs are used on Linux.
72 then an error is returned if a semaphore with the given
80 then two additional arguments must be supplied.
83 argument specifies the permissions to be placed on the new semaphore,
86 (Symbolic definitions for the permissions bits can be obtained by including
88 The permissions settings are masked against the process umask.
89 Both read and write permission should be granted to each class of
90 user that will access the semaphore.
93 argument specifies the initial value for the new semaphore.
96 is specified, and a semaphore with the given
106 returns the address of the new semaphore;
107 this address is used when calling other semaphore-related functions.
114 set to indicate the error.
118 The semaphore exists, but the caller does not have permission to
128 but a semaphore with this
139 consists of just "/", followed by no other characters.
142 The per-process limit on the number of open file descriptors has been reached.
149 The system-wide limit on the total number of open files has been reached.
154 flag was not specified in
156 and no semaphore with this
160 .\" this error can occur if we have a name of the (nonportable) form
161 .\" /dir/name, and the directory /dev/shm/dir does not exist.
170 For an explanation of the terms used in this section, see
178 Interface Attribute Value
181 T} Thread safety MT-Safe
187 POSIX.1-2001, POSIX.1-2008.
190 .BR sem_getvalue (3),