2 .\" Copyright (C) 2006 Michael Kerrisk <mtk.manpages@gmail.com>
4 .\" %%%LICENSE_START(VERBATIM)
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date. The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein. The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
26 .TH SEM_OPEN 3 2012-05-13 "Linux" "Linux Programmer's Manual"
28 sem_open \- initialize and open a named semaphore
31 .BR "#include <fcntl.h>" " /* For O_* constants */"
32 .BR "#include <sys/stat.h>" " /* For mode constants */"
33 .B #include <semaphore.h>
35 .BI "sem_t *sem_open(const char *" name ", int " oflag );
36 .BI "sem_t *sem_open(const char *" name ", int " oflag ", "
37 .BI " mode_t " mode ", unsigned int " value );
40 Link with \fI\-pthread\fP.
43 creates a new POSIX semaphore or opens an existing semaphore.
44 The semaphore is identified by
46 For details of the construction of
53 argument specifies flags that control the operation of the call.
54 (Definitions of the flags values can be obtained by including
60 then the semaphore is created if
61 it does not already exist.
62 The owner (user ID) of the semaphore is set to the effective
63 user ID of the calling process.
64 The group ownership (group ID) is set to the effective group ID
65 of the calling process.
66 .\" In reality the filesystem IDs are used on Linux.
73 then an error is returned if a semaphore with the given
81 then two additional arguments must be supplied.
84 argument specifies the permissions to be placed on the new semaphore,
87 (Symbolic definitions for the permissions bits can be obtained by including
89 The permissions settings are masked against the process umask.
90 Both read and write permission should be granted to each class of
91 user that will access the semaphore.
94 argument specifies the initial value for the new semaphore.
97 is specified, and a semaphore with the given
107 returns the address of the new semaphore;
108 this address is used when calling other semaphore-related functions.
115 set to indicate the error.
119 The semaphore exists, but the caller does not have permission to
129 but a semaphore with this
140 consists of just "/", followed by no other characters.
143 The process already has the maximum number of files and open.
150 The system limit on the total number of open files has been reached.
155 flag was not specified in
157 and no semaphore with this
161 .\" this error can occur if we have a name of the (nonportable) form
162 .\" /dir/name, and the directory /dev/shm/dir does not exist.
174 .BR sem_getvalue (3),