United States-English |
|
|
HP-UX Reference > Ssem_open(2)HP-UX 11i Version 3: February 2007 |
|
NAMEsem_open — create/open a named POSIX semaphore SYNOPSIS#include <sys/semaphore.h> sem_t * sem_open(const char *name, int oflag, mode_t mode, unsigned int value); DESCRIPTIONsem_open() is used to open or create a named semaphore. A successful call to sem_open() will create a descriptor for the semaphore specified by name. The pointer to the semaphore returned by sem_open() can be used to access the semaphore associated with name in subsequent operations. The name argument points to a string referring to a semaphore. It should begin with a "/" and shall conform to pathname rules except that no path component should be "." or "..". The oflag argument specifies whether a semaphore is to be created or not. The following bits in it may be set:
The mode and value arguments are provided to supply the permissions and the initial value information necessary for creating a new semaphore. To use this function, link in the realtime library by specifying -lrt on the compiler or linker command line. EXAMPLESThe following call to sem_open() will create a new named semaphore if one does not exist, which depends on the flags specified in oflag, has the permissions specified in mode and has an initial value of value. sem_open(name, oflag, mode, value); RETURN VALUEIf the semaphore was created and initialized, sem_open() returns a pointer to a sem_t structure containing the index of the new descriptor. If the semaphore could not be created/initialized, the call returns -1 and sets errno to indicate the error. If the named semaphore is already opened by the calling process, a descriptor and a sem_t structure for the named semaphore already exists for the calling process. A new descriptor is not created and a pointer to the existing sem_t structure is returned for this call. ERRORSsem_open() fails and does not perform the requested operation if any of the following conditions are encountered:
|
Printable version | ||
|