2006-03-25 20:42:27 +00:00
|
|
|
'\" t
|
|
|
|
.\" Hey Emacs! This file is -*- nroff -*- source.
|
|
|
|
.\"
|
2007-09-20 06:52:22 +00:00
|
|
|
.\" Copyright (C) 2006 Michael Kerrisk <mtk.manpages@gmail.com>
|
2006-03-25 20:42:27 +00:00
|
|
|
.\"
|
|
|
|
.\" Permission is granted to make and distribute verbatim copies of this
|
|
|
|
.\" manual provided the copyright notice and this permission notice are
|
|
|
|
.\" preserved on all copies.
|
|
|
|
.\"
|
|
|
|
.\" Permission is granted to copy and distribute modified versions of this
|
|
|
|
.\" manual under the conditions for verbatim copying, provided that the
|
|
|
|
.\" entire resulting derived work is distributed under the terms of a
|
|
|
|
.\" permission notice identical to this one.
|
2007-04-12 22:42:49 +00:00
|
|
|
.\"
|
2006-03-25 20:42:27 +00:00
|
|
|
.\" Since the Linux kernel and libraries are constantly changing, this
|
|
|
|
.\" manual page may be incorrect or out-of-date. The author(s) assume no
|
|
|
|
.\" responsibility for errors or omissions, or for damages resulting from
|
2008-03-18 14:47:54 +00:00
|
|
|
.\" the use of the information contained herein. The author(s) may not
|
|
|
|
.\" have taken the same level of care in the production of this manual,
|
|
|
|
.\" which is licensed free of charge, as they might when working
|
|
|
|
.\" professionally.
|
2007-04-12 22:42:49 +00:00
|
|
|
.\"
|
2006-03-25 20:42:27 +00:00
|
|
|
.\" Formatted or processed versions of this manual, if unaccompanied by
|
|
|
|
.\" the source, must acknowledge the copyright and authors of this work.
|
|
|
|
.\"
|
2009-02-20 07:22:00 +00:00
|
|
|
.TH SEM_OPEN 3 2009-02-20 "Linux" "Linux Programmer's Manual"
|
2006-03-25 20:42:27 +00:00
|
|
|
.SH NAME
|
2007-06-08 09:56:56 +00:00
|
|
|
sem_open \- initialize and open a named semaphore
|
2006-03-25 20:42:27 +00:00
|
|
|
.SH SYNOPSIS
|
|
|
|
.nf
|
2008-03-10 09:49:26 +00:00
|
|
|
.BR "#include <fcntl.h>" " /* For O_* constants */"
|
2008-06-05 20:14:50 +00:00
|
|
|
.BR "#include <sys/stat.h>" " /* For mode constants */"
|
2006-03-25 20:42:27 +00:00
|
|
|
.B #include <semaphore.h>
|
|
|
|
.sp
|
|
|
|
.BI "sem_t *sem_open(const char *" name ", int " oflag );
|
|
|
|
.BI "sem_t *sem_open(const char *" name ", int " oflag ", "
|
|
|
|
.BI " mode_t " mode ", unsigned int " value );
|
|
|
|
.fi
|
2008-03-10 08:29:29 +00:00
|
|
|
.sp
|
|
|
|
Link with \fI\-lrt\fP or \fI\-pthread\fP.
|
2006-03-25 20:42:27 +00:00
|
|
|
.SH DESCRIPTION
|
|
|
|
.BR sem_open ()
|
|
|
|
creates a new POSIX semaphore or opens an existing semaphore.
|
|
|
|
The semaphore is identified by
|
|
|
|
.IR name .
|
2007-04-12 22:42:49 +00:00
|
|
|
For details of the construction of
|
|
|
|
.IR name ,
|
2006-03-25 20:42:27 +00:00
|
|
|
see
|
|
|
|
.BR sem_overview (7).
|
|
|
|
|
|
|
|
The
|
|
|
|
.I oflag
|
|
|
|
argument specifies flags that control the operation of the call.
|
2008-03-10 09:49:26 +00:00
|
|
|
(Definitions of the flags values can be obtained by including
|
|
|
|
.IR <fcntl.h> .)
|
2006-03-25 20:42:27 +00:00
|
|
|
If
|
|
|
|
.B O_CREAT
|
2007-04-12 22:42:49 +00:00
|
|
|
is specified in
|
|
|
|
.IR oflag ,
|
|
|
|
then the semaphore is created if
|
2006-03-25 20:42:27 +00:00
|
|
|
it does not already exist.
|
2007-04-12 22:42:49 +00:00
|
|
|
The owner (user ID) of the semaphore is set to the effective
|
|
|
|
user ID of the calling process.
|
|
|
|
The group ownership (group ID) is set to the effective group ID
|
2006-03-25 20:42:27 +00:00
|
|
|
of the calling process.
|
|
|
|
.\" In reality the file system IDs are used on Linux.
|
|
|
|
If both
|
|
|
|
.B O_CREAT
|
|
|
|
and
|
|
|
|
.B O_EXCL
|
|
|
|
are specified in
|
|
|
|
.IR oflag ,
|
|
|
|
then an error is returned if a semaphore with the given
|
|
|
|
.I name
|
|
|
|
already exists.
|
|
|
|
.PP
|
2007-04-12 22:42:49 +00:00
|
|
|
If
|
2006-03-25 20:42:27 +00:00
|
|
|
.B O_CREAT
|
2007-04-12 22:42:49 +00:00
|
|
|
is specified in
|
2006-03-25 20:42:27 +00:00
|
|
|
.IR oflag ,
|
|
|
|
then two additional arguments must be supplied.
|
|
|
|
The
|
|
|
|
.I mode
|
|
|
|
argument specifies the permissions to be placed on the new semaphore,
|
|
|
|
as for
|
|
|
|
.BR open (2).
|
2008-03-10 09:49:26 +00:00
|
|
|
(Symbolic definitions for the permissions bits can be obtained by including
|
|
|
|
.IR <sys/stat.h> .)
|
2006-03-25 20:42:27 +00:00
|
|
|
The permissions settings are masked against the process umask.
|
2007-04-12 22:42:49 +00:00
|
|
|
Both read and write permission should be granted to each class of
|
2006-03-25 20:42:27 +00:00
|
|
|
user that will access the semaphore.
|
2007-04-12 22:42:49 +00:00
|
|
|
The
|
2006-03-25 20:42:27 +00:00
|
|
|
.I value
|
|
|
|
argument specifies the initial value for the new semaphore.
|
2007-04-12 22:42:49 +00:00
|
|
|
If
|
2006-03-25 20:42:27 +00:00
|
|
|
.B O_CREAT
|
|
|
|
is specified, and a semaphore with the given
|
|
|
|
.I name
|
|
|
|
already exists, then
|
|
|
|
.I mode
|
|
|
|
and
|
|
|
|
.I value
|
|
|
|
are ignored.
|
|
|
|
.SH RETURN VALUE
|
|
|
|
On success,
|
|
|
|
.BR sem_open ()
|
2007-04-12 22:42:49 +00:00
|
|
|
returns the address of the new semaphore;
|
2006-06-03 01:26:30 +00:00
|
|
|
this address is used when calling other semaphore-related functions.
|
2007-04-12 22:42:49 +00:00
|
|
|
On error,
|
2006-03-25 20:42:27 +00:00
|
|
|
.BR sem_open ()
|
2007-04-12 22:42:49 +00:00
|
|
|
returns
|
2006-03-25 20:42:27 +00:00
|
|
|
.BR SEM_FAILED ,
|
|
|
|
with
|
|
|
|
.I errno
|
|
|
|
set to indicate the error.
|
|
|
|
.SH ERRORS
|
|
|
|
.TP
|
2006-12-27 01:47:20 +00:00
|
|
|
.B EACCES
|
2007-04-12 22:42:49 +00:00
|
|
|
The semaphore exists, but the caller does not have permission to
|
2006-03-25 20:42:27 +00:00
|
|
|
open it.
|
|
|
|
.TP
|
|
|
|
.B EEXIST
|
|
|
|
Both
|
|
|
|
.B O_CREAT
|
|
|
|
and
|
|
|
|
.B O_EXCL
|
2007-04-12 22:42:49 +00:00
|
|
|
were specified in
|
2006-03-25 20:42:27 +00:00
|
|
|
.IR oflag ,
|
2007-04-12 22:42:49 +00:00
|
|
|
but a semaphore with this
|
2006-03-25 20:42:27 +00:00
|
|
|
.I name
|
|
|
|
already exists.
|
|
|
|
.TP
|
|
|
|
.B EINVAL
|
2007-04-12 22:42:49 +00:00
|
|
|
.I value
|
2006-03-25 20:42:27 +00:00
|
|
|
was greater than
|
|
|
|
.BR SEM_VALUE_MAX .
|
|
|
|
.TP
|
2009-02-20 01:52:43 +00:00
|
|
|
.B EINVAL
|
|
|
|
.I name
|
|
|
|
consists of just "/", followed by no other characters.
|
|
|
|
.TP
|
2006-03-25 20:42:27 +00:00
|
|
|
.B EMFILE
|
|
|
|
The process already has the maximum number of files and open.
|
|
|
|
.TP
|
|
|
|
.B ENAMETOOLONG
|
2007-09-20 16:26:31 +00:00
|
|
|
.I name
|
2006-03-25 20:42:27 +00:00
|
|
|
was too long.
|
|
|
|
.TP
|
|
|
|
.B ENFILE
|
|
|
|
The system limit on the total number of open files has been reached.
|
|
|
|
.TP
|
|
|
|
.B ENOENT
|
|
|
|
The
|
|
|
|
.B O_CREAT
|
2007-04-12 22:42:49 +00:00
|
|
|
flag was not specified in
|
2009-02-20 01:57:20 +00:00
|
|
|
.IR oflag
|
2007-04-12 22:42:49 +00:00
|
|
|
and no semaphore with this
|
2006-03-25 20:42:27 +00:00
|
|
|
.I name
|
2009-02-20 01:57:20 +00:00
|
|
|
exists;
|
|
|
|
or,
|
execve.2, fallocate.2, futex.2, sched_rr_get_interval.2, select_tut.2, shmget.2, timer_getoverrun.2, times.2, pthread_attr_init.3, pthread_attr_setaffinity_np.3, pthread_cleanup_push_defer_np.3, pthread_getattr_np.3, pthread_self.3, pthread_setaffinity_np.3, pthread_tryjoin_np.3, sem_open.3, stdin.3, rtc.4, tty_ioctl.4, unix.7: Global fix: s/non-portable/nonportable/
The tendency in English, as prescribed in style guides like
Chicago MoS, is towards removing hyphens after prefixes
like "non-" etc.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-01-16 16:46:09 +00:00
|
|
|
.\" this error can occur if we have a name of the (nonportable) form
|
2009-02-20 01:57:20 +00:00
|
|
|
.\" /dir/name, and the directory /dev/shm/dir does not exist.
|
|
|
|
.B O_CREAT
|
|
|
|
was specified, but
|
|
|
|
.I name
|
|
|
|
wasn't well formed.
|
2006-03-25 20:42:27 +00:00
|
|
|
.TP
|
|
|
|
.B ENOMEM
|
|
|
|
Insufficient memory.
|
|
|
|
.SH CONFORMING TO
|
|
|
|
POSIX.1-2001.
|
|
|
|
.SH "SEE ALSO"
|
|
|
|
.BR sem_close (3),
|
|
|
|
.BR sem_getvalue (3),
|
|
|
|
.BR sem_post (3),
|
|
|
|
.BR sem_unlink (3),
|
|
|
|
.BR sem_wait (3),
|
|
|
|
.BR sem_overview (7)
|