1SEM_OPEN(3) Linux Programmer's Manual SEM_OPEN(3)
2
3
4
6 sem_open - initialise and open a named semaphore
7
9 #include <semaphore.h>
10
11 sem_t *sem_open(const char *name, int oflag);
12 sem_t *sem_open(const char *name, int oflag,
13 mode_t mode, unsigned int value);
14
16 sem_open() creates a new POSIX semaphore or opens an existing sema‐
17 phore. The semaphore is identified by name. For details of the con‐
18 struction of name, see sem_overview(7).
19
20 The oflag argument specifies flags that control the operation of the
21 call. If O_CREAT is specified in oflag, then the semaphore is created
22 if it does not already exist. The owner (user ID) of the semaphore is
23 set to the effective user ID of the calling process. The group owner‐
24 ship (group ID) is set to the effective group ID of the calling
25 process. If both O_CREAT and O_EXCL are specified in oflag, then an
26 error is returned if a semaphore with the given name already exists.
27
28 If O_CREAT is specified in oflag, then two additional arguments must be
29 supplied. The mode argument specifies the permissions to be placed on
30 the new semaphore, as for open(2). The permissions settings are masked
31 against the process umask. Both read and write permission should be
32 granted to each class of user that will access the semaphore. The
33 value argument specifies the initial value for the new semaphore. If
34 O_CREAT is specified, and a semaphore with the given name already
35 exists, then mode and value are ignored.
36
38 On success, sem_open() returns the address of the new semaphore; this
39 address is used when calling other semaphore-related functions. On
40 error, sem_open() returns SEM_FAILED, with errno set to indicate the
41 error.
42
44 EACCES The semaphore exists, but the caller does not have permission to
45 open it.
46
47 EEXIST Both O_CREAT and O_EXCL were specified in oflag, but a semaphore
48 with this name already exists.
49
50 EINVAL value was greater than SEM_VALUE_MAX.
51
52 EMFILE The process already has the maximum number of files and open.
53
54 ENAMETOOLONG
55 name was too long.
56
57 ENFILE The system limit on the total number of open files has been
58 reached.
59
60 ENOENT The O_CREAT flag was not specified in oflag, and no semaphore
61 with this name exists.
62
63 ENOMEM Insufficient memory.
64
66 POSIX.1-2001.
67
69 sem_close(3), sem_getvalue(3), sem_post(3), sem_unlink(3), sem_wait(3),
70 sem_overview(7)
71
72
73
74Linux 2.6.16 2006-03-25 SEM_OPEN(3)