1SEM_OPEN(3)                Linux Programmer's Manual               SEM_OPEN(3)
2
3
4

NAME

6       sem_open - initialize and open a named semaphore
7

SYNOPSIS

9       #include <fcntl.h>           /* For O_* constants */
10       #include <sys/stat.h>        /* For mode constants */
11       #include <semaphore.h>
12
13       sem_t *sem_open(const char *name, int oflag);
14       sem_t *sem_open(const char *name, int oflag,
15                       mode_t mode, unsigned int value);
16
17       Link with -lrt or -pthread.
18

DESCRIPTION

20       sem_open()  creates  a  new  POSIX semaphore or opens an existing sema‐
21       phore.  The semaphore is identified by name.  For details of  the  con‐
22       struction of name, see sem_overview(7).
23
24       The  oflag  argument  specifies flags that control the operation of the
25       call.  (Definitions of the flags values can be  obtained  by  including
26       <fcntl.h>.)   If  O_CREAT  is specified in oflag, then the semaphore is
27       created if it does not already exist.  The owner (user ID) of the sema‐
28       phore  is  set  to  the  effective user ID of the calling process.  The
29       group ownership (group ID) is set to the  effective  group  ID  of  the
30       calling  process.   If  both O_CREAT and O_EXCL are specified in oflag,
31       then an error is returned if a semaphore with the  given  name  already
32       exists.
33
34       If O_CREAT is specified in oflag, then two additional arguments must be
35       supplied.  The mode argument specifies the permissions to be placed  on
36       the  new semaphore, as for open(2).  (Symbolic definitions for the per‐
37       missions bits can be obtained by including <sys/stat.h>.)  The  permis‐
38       sions  settings  are  masked  against the process umask.  Both read and
39       write permission should be granted to each  class  of  user  that  will
40       access  the  semaphore.  The value argument specifies the initial value
41       for the new semaphore.  If O_CREAT is specified, and a  semaphore  with
42       the given name already exists, then mode and value are ignored.
43

RETURN VALUE

45       On  success,  sem_open() returns the address of the new semaphore; this
46       address is used when calling  other  semaphore-related  functions.   On
47       error,  sem_open()  returns  SEM_FAILED, with errno set to indicate the
48       error.
49

ERRORS

51       EACCES The semaphore exists, but the caller does not have permission to
52              open it.
53
54       EEXIST Both O_CREAT and O_EXCL were specified in oflag, but a semaphore
55              with this name already exists.
56
57       EINVAL value was greater than SEM_VALUE_MAX.
58
59       EINVAL name consists of just "/", followed by no other characters.
60
61       EMFILE The process already has the maximum number of files and open.
62
63       ENAMETOOLONG
64              name was too long.
65
66       ENFILE The system limit on the total number  of  open  files  has  been
67              reached.
68
69       ENOENT The  O_CREAT  flag  was  not specified in oflag and no semaphore
70              with this name exists;  or,  O_CREAT  was  specified,  but  name
71              wasn't well formed.
72
73       ENOMEM Insufficient memory.
74

CONFORMING TO

76       POSIX.1-2001.
77

SEE ALSO

79       sem_close(3), sem_getvalue(3), sem_post(3), sem_unlink(3), sem_wait(3),
80       sem_overview(7)
81

COLOPHON

83       This page is part of release 3.22 of the Linux  man-pages  project.   A
84       description  of  the project, and information about reporting bugs, can
85       be found at http://www.kernel.org/doc/man-pages/.
86
87
88
89Linux                             2009-02-20                       SEM_OPEN(3)
Impressum