Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

semget(2) [opensolaris man page]

semget(2)							   System Calls 							 semget(2)

NAME
semget - get set of semaphores SYNOPSIS
#include <sys/types.h> #include <sys/ipc.h> #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 associated data structure and set containing nsems semaphores (see Intro(2)) are created for key if one of the following is true: o key is equal to IPC_PRIVATE. o key does not already have a semaphore identifier associated with it, and (semflg&IPC_CREAT) is true. On creation, the data structure associated with the new semaphore identifier is initialized as follows: o sem_perm.cuid, sem_perm.uid, sem_perm.cgid, and sem_perm.gid are set equal to the effective user ID and effective group ID, respectively, of the calling process. o The access permission bits of sem_perm.mode are set equal to the access permission bits of semflg. o sem_nsems is set equal to the value of nsems. o sem_otime is set equal to 0 and sem_ctime is set equal to the current time. RETURN VALUES
Upon successful completion, a non-negative integer representing a semaphore identifier is returned. Otherwise, -1 is returned and errno is set to indicate the error. ERRORS
The semget() function will fail if: EACCES A semaphore identifier exists for key, but operation permission (see Intro(2)) as specified by the low-order 9 bits of semflg would not be granted. EEXIST A semaphore identifier exists for key but both (semflg&IPC_CREAT) and (semflg&IPC_EXCL) are both true. EINVAL The nsems argument is either less than or equal to 0 or greater than the system-imposed limit. See NOTES. 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 0. ENOENT A semaphore identifier does not exist for key and (semflg&IPC_CREAT) is false. ENOSPC A semaphore identifier is to be created but the system-imposed limit on the maximum number of allowed semaphores or semaphore identifiers system-wide would be exceeded. See NOTES. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ SEE ALSO
ipcrm(1), ipcs(1), rctladm(1M), Intro(2), semctl(2), semop(2), setrctl(2), ftok(3C), attributes(5), standards(5) NOTES
The system-imposed limit on the value of the nsems argument is the maintained on a per-process basis using the process.max-sem-nsems resource control. The system-imposed limit on the number of semaphore identifiers is maintained on a per-project basis using the project.max-sem-ids resource control. The zone.max-sem-ids resource control limis the total number of semaphore identifiers that can be allocated by a zone. See rctladm(1M) and setrctl(2) for information about using resource controls. SunOS 5.11 14 Aug 2006 semget(2)

Check Out this Related Man Page

semget(2)							System Calls Manual							 semget(2)

NAME
semget - Returns (and possibly creates) a semaphore ID SYNOPSIS
#include <sys/sem.h> int semget( key_t key, int nsems, int semflg); Application developers may want to specify #include statements for <sys/types.h> and <sys/ipc.h> before the one for <sys/sem.h> if programs are being developed for multiple platforms. The additional #include statements are not required on Tru64 UNIX systems or by ISO or X/Open standards, but may be required on other vendors' systems that conform to these standards. STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: semget(): XPG4, XPG4-UNIX Refer to the standards(5) reference page for more information about industry standards and associated tags. PARAMETERS
Specifies the key that identifies the semaphore set. The value for the key parameter can be IPC_PRIVATE or a random number other than 0 (zero). To ensure that you receive a new, unused entry in the semaphore table, specify IPC_PRIVATE as the value of key. Specifies the number of semaphores to create in the semaphore set. Specifies the creation flags. Possible values are as follows: If the key specified does not exist, the semget function creates a semaphore ID using the specified key. If the specified key exists, and IPC_EXCL is not set, the semaphore id for the specified key is returned. If the specified key exists and IPC_EXCL is set, the semget function fails and returns an error. Specifies that you want exclusive access to the semaphore set. If the specified key already exists, the semget function fails and returns an error notification. DESCRIPTION
The system defines sets of semaphores in a system-wide table, with each set being an entry in the table. The semget() function returns an ID that identifies the semaphore set's entry in the table. You determine which semaphore set's ID is returned by specifying the key param- eter. The semget() function creates a semaphore set containing nsems semaphores and returns its ID in the following situations: The key parameter is IPC_PRIVATE. The key parameter does not already exist as an entry in the semaphore table and the IPC_CREAT flag is set. To create a semaphore set, the semget() function creates and initializes a structure of type semid_ds, which is defined as follows: struct semid_ds { struct ipc_perm sem_perm; struct sem *sem_base; ushort_t sem_nsems; time_t sem_otime; time_t sem_ctime; }; For a complete description of this structure, see semid_ds(4). The semget() function initializes the structure as follows: The sem_perm.cuid and sem_perm.uid fields are set equal to the effective user ID of the calling process. The sem_perm.cgid and sem_perm.gid fields are set equal to the effective group ID of the calling process. The low-order nine bits of sem_perm.mode are set equal to the low- order nine bits of semflg. The sem_nsems field is set equal to the value of nsems. The sem_otime field is set equal to zero (0) and the sem_ctime field is set equal to the current time. The individual semaphores within a set are implemented using the sem structure. (For more information about this structure, see the <sys/sem.h> header file.) The semget function does not initialize the sem structure associated with each semaphore in the set. The indi- vidual semaphores are initialized when you call the semctl function with the SETVAL or SETALL command. RETURN VALUES
Upon successful completion, the semget() function returns a semaphore identifier. If the semget function fails, it returns a value of -1 and sets errno to indicate the error. ERRORS
The semget function sets errno to the specified values for the following conditions: A semaphore ID already exists for the key parameter, but operation permission as specified by the low-order nine bits of the semflg parameter was not granted. A semaphore ID already exists for the key parameter, but IPC_CREAT and IPC_EXCL were used for the semflg parameter. The value of the nsems parameter is less than or equal to 0 (zero) or greater than the system-defined limit. Or, a semaphore ID already exists for the key parameter, but the number of semaphores in the set is less than the nsems parameter, and the nsems parameter is not equal to 0 (zero). A semaphore ID does not exist for the key parameter and IPC_CREAT was not set. An attempt to create a new semaphore ID exceeded the system-wide limit on the size of the semaphore table. RELATED INFORMATION
Functions: semctl(2), semop(2), table(2), ftok(3) Files: semid_ds(4), sysconfigtab(4) Standards: standards(5) delim off semget(2)
Man Page