semget()

get semaphore identifier 

Function


SYNOPSIS

#include <sys/sem.h>

int semget(key_t key, int nsems, int semflg);


DESCRIPTION

The semget() function returns the semaphore identifier associated with key. A semaphore identifier and an associated set containing nsems semaphores are created for key if key is equal to IPC_PRIVATE, or key does not already have a semaphore identifier associated with it, and (semflg & IPC_CREAT) is non-zero.

Upon creation, the internal attributes associated with the new semaphore identifier are initialized as follows:

You must explicitly remove semaphore identifiers after the last reference to them has been removed.

The ftok() function can be used to generate unique keys that can be passed as values for key.


PARAMETERS

key 

Specifies either IPC_PRIVATE or a system-wide unique key.

nsems 

Is the number of semaphores in the set associated with the semaphore ID.

semflg 

Is a flag indicating specific semaphore conditions and options to implement.


RETURN VALUES

If successful, semget() returns a semaphore identifier. On failure, semget() returns -1 and sets errno to one of the following:

EACCES 

A semaphore identifier exists for key, but operation permission as specified by permission bits of semflg would not be granted.

EEXIST 

A semaphore identifier exists for key but (semflg & IPC_CREAT) and (semflg & IPC_EXCL) are both non-zero.

EINVAL 

A semaphore identifier exists for key, but the number of semaphores in the set associated with it is less than nsems, and nsems is not equal to zero.

EINVAL 

nsems is either less than or equal to zero or greater than the system imposed limit.

ENOENT 

A semaphore identifier does not exist for key and (semflg & IPC_CREAT) is zero.

ENOSPC 

A semaphore identifier is to be created but the system-imposed limit on the maximum number of allowed semaphore identifiers system wide would be exceeded.


CONFORMANCE

UNIX 98.


MULTITHREAD SAFETY LEVEL

MT-Safe.


PORTING ISSUES

NuTCRACKER Platform semaphores are not implemented in terms of Win32 semaphores; therefore, they cannot be shared with Win32 applications.


AVAILABILITY

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


SEE ALSO

Functions:
ftok(), semctl(), semop()


PTC MKS Toolkit 10.5 Documentation Build 40.