man-pages/man3/sem_open.3

168 lines
4.1 KiB
Groff
Raw Normal View History

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.
.\"
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
.\" 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.
.\"
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.
.\"
2008-05-29 08:02:43 +00:00
.TH SEM_OPEN 3 2008-05-29 "Linux" "Linux Programmer's Manual"
2006-03-25 20:42:27 +00:00
.SH NAME
sem_open \- initialize and open a named semaphore
2006-03-25 20:42:27 +00:00
.SH SYNOPSIS
.nf
.BR "#include <fcntl.h>" " /* For O_* constants */"
.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
.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 .
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.
(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
is specified in
.IR oflag ,
then the semaphore is created if
2006-03-25 20:42:27 +00:00
it does not already exist.
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
If
2006-03-25 20:42:27 +00:00
.B O_CREAT
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).
(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.
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.
The
2006-03-25 20:42:27 +00:00
.I value
argument specifies the initial value for the new semaphore.
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 ()
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.
On error,
2006-03-25 20:42:27 +00:00
.BR sem_open ()
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
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
were specified in
2006-03-25 20:42:27 +00:00
.IR oflag ,
but a semaphore with this
2006-03-25 20:42:27 +00:00
.I name
already exists.
.TP
.B EINVAL
.I value
2006-03-25 20:42:27 +00:00
was greater than
.BR SEM_VALUE_MAX .
.TP
.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
flag was not specified in
2006-03-25 20:42:27 +00:00
.IR oflag ,
and no semaphore with this
2006-03-25 20:42:27 +00:00
.I name
exists.
.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)