]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/sem_open.3
fuse.4: fuse_entry_out: rework discussion of uniqueness of nodeid + generation
[thirdparty/man-pages.git] / man3 / sem_open.3
CommitLineData
2c731798 1'\" t
c11b1abf 2.\" Copyright (C) 2006 Michael Kerrisk <mtk.manpages@gmail.com>
2c731798 3.\"
93015253 4.\" %%%LICENSE_START(VERBATIM)
2c731798
MK
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.
8.\"
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.
c13182ef 13.\"
2c731798
MK
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
10d76543
MK
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
20.\" professionally.
c13182ef 21.\"
2c731798
MK
22.\" Formatted or processed versions of this manual, if unaccompanied by
23.\" the source, must acknowledge the copyright and authors of this work.
4b72fb64 24.\" %%%LICENSE_END
2c731798 25.\"
29b41e74 26.TH SEM_OPEN 3 2015-12-28 "Linux" "Linux Programmer's Manual"
2c731798 27.SH NAME
d9bfdb9c 28sem_open \- initialize and open a named semaphore
2c731798
MK
29.SH SYNOPSIS
30.nf
87d17de4 31.BR "#include <fcntl.h>" " /* For O_* constants */"
84c517a4 32.BR "#include <sys/stat.h>" " /* For mode constants */"
2c731798
MK
33.B #include <semaphore.h>
34.sp
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 );
38.fi
fce1dd17 39.sp
2c5f8c8c 40Link with \fI\-pthread\fP.
2c731798
MK
41.SH DESCRIPTION
42.BR sem_open ()
43creates a new POSIX semaphore or opens an existing semaphore.
44The semaphore is identified by
45.IR name .
c13182ef
MK
46For details of the construction of
47.IR name ,
2c731798
MK
48see
49.BR sem_overview (7).
50
51The
52.I oflag
53argument specifies flags that control the operation of the call.
87d17de4
MK
54(Definitions of the flags values can be obtained by including
55.IR <fcntl.h> .)
2c731798
MK
56If
57.B O_CREAT
c13182ef
MK
58is specified in
59.IR oflag ,
60then the semaphore is created if
2c731798 61it does not already exist.
c13182ef
MK
62The owner (user ID) of the semaphore is set to the effective
63user ID of the calling process.
64The group ownership (group ID) is set to the effective group ID
2c731798 65of the calling process.
9ee4a2b6 66.\" In reality the filesystem IDs are used on Linux.
2c731798
MK
67If both
68.B O_CREAT
69and
70.B O_EXCL
71are specified in
72.IR oflag ,
73then an error is returned if a semaphore with the given
74.I name
75already exists.
76.PP
c13182ef 77If
2c731798 78.B O_CREAT
c13182ef 79is specified in
2c731798
MK
80.IR oflag ,
81then two additional arguments must be supplied.
82The
83.I mode
84argument specifies the permissions to be placed on the new semaphore,
85as for
86.BR open (2).
87d17de4
MK
87(Symbolic definitions for the permissions bits can be obtained by including
88.IR <sys/stat.h> .)
2c731798 89The permissions settings are masked against the process umask.
c13182ef 90Both read and write permission should be granted to each class of
2c731798 91user that will access the semaphore.
c13182ef 92The
2c731798
MK
93.I value
94argument specifies the initial value for the new semaphore.
c13182ef 95If
2c731798
MK
96.B O_CREAT
97is specified, and a semaphore with the given
98.I name
99already exists, then
100.I mode
101and
102.I value
103are ignored.
104.SH RETURN VALUE
105On success,
106.BR sem_open ()
c13182ef 107returns the address of the new semaphore;
7145b9a9 108this address is used when calling other semaphore-related functions.
c13182ef 109On error,
2c731798 110.BR sem_open ()
c13182ef 111returns
2c731798
MK
112.BR SEM_FAILED ,
113with
114.I errno
115set to indicate the error.
116.SH ERRORS
117.TP
1b3fc756 118.B EACCES
c13182ef 119The semaphore exists, but the caller does not have permission to
2c731798
MK
120open it.
121.TP
122.B EEXIST
123Both
124.B O_CREAT
125and
126.B O_EXCL
c13182ef 127were specified in
2c731798 128.IR oflag ,
c13182ef 129but a semaphore with this
2c731798
MK
130.I name
131already exists.
132.TP
133.B EINVAL
c13182ef 134.I value
2c731798
MK
135was greater than
136.BR SEM_VALUE_MAX .
137.TP
18fe47e0
MK
138.B EINVAL
139.I name
140consists of just "/", followed by no other characters.
141.TP
2c731798 142.B EMFILE
26c32fab 143The per-process limit on the number of open file descriptors has been reached.
2c731798
MK
144.TP
145.B ENAMETOOLONG
0daa9e92 146.I name
2c731798
MK
147was too long.
148.TP
149.B ENFILE
e258766b 150The system-wide limit on the total number of open files has been reached.
2c731798
MK
151.TP
152.B ENOENT
153The
154.B O_CREAT
c13182ef 155flag was not specified in
db2fff8c 156.IR oflag
c13182ef 157and no semaphore with this
2c731798 158.I name
db2fff8c
JTT
159exists;
160or,
d603cc27 161.\" this error can occur if we have a name of the (nonportable) form
db2fff8c
JTT
162.\" /dir/name, and the directory /dev/shm/dir does not exist.
163.B O_CREAT
164was specified, but
165.I name
166wasn't well formed.
2c731798
MK
167.TP
168.B ENOMEM
169Insufficient memory.
ca6b4c15
ZL
170.SH ATTRIBUTES
171For an explanation of the terms used in this section, see
172.BR attributes (7).
173.TS
174allbox;
175lb lb lb
176l l l.
177Interface Attribute Value
178T{
179.BR sem_open ()
180T} Thread safety MT-Safe
181.TE
182
2c731798 183.SH CONFORMING TO
64131c24 184POSIX.1-2001, POSIX.1-2008.
47297adb 185.SH SEE ALSO
2c731798
MK
186.BR sem_close (3),
187.BR sem_getvalue (3),
188.BR sem_post (3),
189.BR sem_unlink (3),
190.BR sem_wait (3),
191.BR sem_overview (7)