| Skip Navigation Links | |
| Exit Print View | |
![]() | man pages section 3: Basic Library Functions Oracle Solaris 11 Information Library |
enable_extended_FILE_stdio(3C)
posix_spawnattr_getschedparam(3C)
posix_spawnattr_getschedpolicy(3C)
posix_spawnattr_getsigdefault(3C)
posix_spawnattr_getsigignore_np(3C)
posix_spawnattr_getsigmask(3C)
posix_spawnattr_setschedparam(3C)
posix_spawnattr_setschedpolicy(3C)
posix_spawnattr_setsigdefault(3C)
posix_spawnattr_setsigignore_np(3C)
posix_spawnattr_setsigmask(3C)
posix_spawn_file_actions_addclose(3C)
posix_spawn_file_actions_addclosefrom_np(3C)
posix_spawn_file_actions_adddup2(3C)
posix_spawn_file_actions_addopen(3C)
posix_spawn_file_actions_destroy(3C)
posix_spawn_file_actions_init(3C)
pthread_attr_getdetachstate(3C)
pthread_attr_getinheritsched(3C)
pthread_attr_getschedparam(3C)
pthread_attr_getschedpolicy(3C)
pthread_attr_setdetachstate(3C)
pthread_attr_setinheritsched(3C)
pthread_attr_setschedparam(3C)
pthread_attr_setschedpolicy(3C)
pthread_barrierattr_destroy(3C)
pthread_barrierattr_getpshared(3C)
pthread_barrierattr_setpshared(3C)
pthread_condattr_getpshared(3C)
pthread_condattr_setpshared(3C)
pthread_cond_reltimedwait_np(3C)
pthread_key_create_once_np(3C)
pthread_mutexattr_getprioceiling(3C)
pthread_mutexattr_getprotocol(3C)
pthread_mutexattr_getpshared(3C)
pthread_mutexattr_getrobust(3C)
pthread_mutexattr_setprioceiling(3C)
pthread_mutexattr_setprotocol(3C)
pthread_mutexattr_setpshared(3C)
pthread_mutexattr_setrobust(3C)
pthread_mutex_getprioceiling(3C)
pthread_mutex_reltimedlock_np(3C)
pthread_mutex_setprioceiling(3C)
pthread_rwlockattr_destroy(3C)
pthread_rwlockattr_getpshared(3C)
pthread_rwlockattr_setpshared(3C)
pthread_rwlock_reltimedrdlock_np(3C)
pthread_rwlock_reltimedwrlock_np(3C)
pthread_rwlock_timedrdlock(3C)
pthread_rwlock_timedwrlock(3C)
rctlblk_get_enforced_value(3C)
- initialize/open a named semaphore
#include <semaphore.h>sem_t *sem_open(const char *name,intoflag,/* unsigned longmode,unsigned intvalue */ ...);
Thesem_open() function establishes a connection between a named semaphore and aprocess (or LWP or thread). Following a call tosem_open() with semaphorenamename, the process may reference the semaphore associated withname usingthe address returned from the call. This semaphore may be used insubsequent calls tosem_wait(3C),sem_trywait(3C),sem_post(3C), andsem_close(3C). The semaphore remains usableby this process until the semaphore is closed by a successful calltosem_close(3C),_Exit(2), or one of theexec functions.
Theoflag argument controls whether the semaphore is created or merely accessedby the call tosem_open(). The following flag bits may be setinoflag:
This flag is used to create a semaphore if it does not already exist. IfO_CREAT is set and the semaphore already exists, thenO_CREAT has no effect, except as noted underO_EXCL. Otherwise,sem_open() creates a named semaphore. TheO_CREAT flag requires a third and a fourth argument:mode, which is of typemode_t, andvalue, which is of typeunsigned int. The semaphore is created with an initial value ofvalue. Valid initial values for semaphores are less than or equal toSEM_VALUE_MAX.
The user ID of the semaphore is set to the effective user ID of the process; the group ID of the semaphore is set to a system default group ID or to the effective group ID of the process. The permission bits of the semaphore are set to the value of themode argument except those set in the file mode creation mask of the process (seeumask(2)). When bits inmode other than the file permission bits are specified, the effect is unspecified.
After the semaphore namedname has been created bysem_open() with theO_CREAT flag, other processes can connect to the semaphore by callingsem_open() with the same value ofname.
IfO_EXCL andO_CREAT are set,sem_open() fails if the semaphorename exists. The check for the existence of the semaphore and the creation of the semaphore if it does not exist are atomic with respect to other processes executingsem_open() withO_EXCL andO_CREAT set. IfO_EXCL is set andO_CREAT is not set, the effect is undefined.
If flags other thanO_CREAT andO_EXCL are specified in theoflagparameter, the effect is unspecified.
Thename argument points to a string naming a semaphore object. Itis unspecified whether the name appears in the file system and isvisible to functions that take pathnames as arguments. Thename argument conformsto the construction rules for a pathname. The first character ofnamemust be a slash (/) character and the remaining characters ofname cannot include any slash characters. For maximum portability,name should include no more than 14 characters, but this limit is notenforced.
If a process makes multiple successful calls tosem_open() with the samevalue forname, the same semaphore address is returned for each suchsuccessful call, provided that there have been no calls tosem_unlink(3C) forthis semaphore.
References to copies of the semaphore produce undefined results.
Thesem_init(3C) function is used with unnamed semaphores.
Upon successful completion, the function returns the address of the semaphore. Otherwise,it will return a value ofSEM_FAILED and seterrno to indicatethe error. The symbolSEM_FAILED is defined in the header<semaphore.h>. No successfulreturn fromsem_open() will return the valueSEM_FAILED.
If any of the following conditions occur, thesem_open() function will returnSEM_FAILED and seterrno to the corresponding value:
The named semaphore exists and theO_RDWR permissions are denied, or the named semaphore does not exist and permission to create the named semaphore is denied.
O_CREAT andO_EXCL are set and the named semaphore already exists.
Thesem_open() function was interrupted by a signal.
Thesem_open() operation is not supported for the given name, orO_CREAT was set inoflag andvalue is greater thanSEM_VALUE_MAX.
The number of open semaphore descriptors in this process exceedsSEM_NSEMS_MAX, or the number of open file descriptors in this process exceedsOPEN_MAX.
The length ofname string exceedsPATH_MAX, or a pathname component is longer thanNAME_MAX while_POSIX_NO_TRUNC is in effect.
Too many semaphores are currently open in the system.
O_CREAT is not set and the named semaphore does not exist.
There is insufficient space for the creation of the new named semaphore.
Thesem_open() function is not supported by the system.
Seeattributes(5) for descriptions of the following attributes:
|
exec(2),exit(2),umask(2),sem_close(3C),sem_init(3C),sem_post(3C),sem_unlink(3C),sem_wait(3C),sysconf(3C),attributes(5),standards(5)
Copyright © 2011, Oracle and/or its affiliates. All rights reserved.Legal Notices | ![]() ![]() |