sem_t *sem_open(const char *name, int oflag, ...);
The oflag argument controls whether the semaphore is created or
merely accessed by the call to
Creates a semaphore if it does not already exist. If you set O_CREAT when a semaphore does not already exist, it has no effect except as indicated by the O_EXECL flag. If the semaphore does not already exist,
sem_open()creates it. The O_CREAT flag requires two additional arguments: mode of type mode_t, and value of type unsigned int. The value argument specifies the initial value assigned to the newly created semaphore and must be less than or equal to SEM_VALUE_MAX. The effective user ID of the process is assigned as the user ID of the newly created semaphore, while the effective group ID of the process is assigned as the semaphore's group ID. Similarly, the value of the mode argument is used to set the permission bits of the newly created semaphore. Bits set in the file mode creation mask of the process are not set for the semaphore. Once sem_open()has created the semaphore named name with the O_CREAT flag, other processes can connect to the semaphore by calling the sem_open()function with the same name argument.
If oflag has both the O_EXCL and O_CREAT flags sets,
sem_open()fails the specified semaphore already exists. The check for whether semaphore exists and creating the semaphore if it does not exist are atomic with respect to other processes executing sem_open()with O_EXCL and O_CREAT set.
When a process successfully calls the
Referring to copies of sem in other semaphore function calls is not recommended. While the current implementation of the semaphore functions supports the use of copies, there is no guarantee that future implementations will have this support.
Points to a string naming a semaphore object. This must be valid semaphore name. Valid semaphore names are path name beginning with a slash (/).
Controls whether the semaphore is created or merely accessed.
The semaphore name already exists and the permissions given by the oflag argument are denied, or the semaphore does not exist and permission to create it is denied.
The O_CREAT and O_EXCL flags are set in oflag and the named semaphore already exists.
sem_open()operation was interrupted by a signal.
sem_open()operation is not supported for the given name, or O_CREAT was specified in oflag and value was greater than SEM_VALUE_MAX.
Too many semaphore descriptors or file descriptors are currently in use by this process.
The length of the name string is greater than PATH_MAX, or a path name component is longer than NAME_MAX while _POSIX_NO_TRUNC is in effect.
Too many semaphores are currently open in the system.
O_CREAT is not set in oflag and the named semaphore does not exist.
There is insufficient space to create the new named semaphore.
UNIX 03. Derived from the POSIX Realtime Extension (1003.1b-1993/1003.1i-1995)
PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition
sem_close(), sem_post(), sem_trywait(), sem_unlink(), sem_wait(), semctl(), semget(), semop()
PTC MKS Toolkit 10.3 Documentation Build 39.