Home
Main website
Display Sidebar
Hide Ads
Recent Changes
View Source:
semget(2)
Edit
PageHistory
Diff
Info
LikePages
SEMGET !!!SEMGET NAME SYNOPSIS DESCRIPTION RETURN VALUE ERRORS NOTES BUGS CONFORMING TO SEE ALSO ---- !!NAME semget - get a semaphore set identifier !!SYNOPSIS __# include ____int semget ( key_t__ ''key''__, int__ ''nsems''__, int__ ''semflg'' __)__ !!DESCRIPTION The function returns the semaphore set identifier associated to the value of the argument ''key''. A new set of ''nsems'' semaphores is created if ''key'' has value __IPC_PRIVATE__ or ''key'' isn't __IPC_PRIVATE__, no existing semaphore set is associated to ''key'', and __IPC_CREAT__ is asserted in ''semflg'' (i.e. ''semflg'' ''IPC_CREAT__ isn't zero). The presence in ''semflg'' of the fields __IPC_CREAT__ and __IPC_EXCL__ plays the same role, with respect to the existence of the semaphore set, as the presence of __O_CREAT__ and __O_EXCL__ in the mode argument of the open(2) system call: i.e. the __semget__ function fails if ''semflg'' asserts both __IPC_CREAT__ and __IPC_EXCL__ and a semaphore set already exists for ''key''. Upon creation, the lower 9 bits of the argument ''semflg'' define the access permissions (for owner, group and others) to the semaphore set in the same format, and with the same meaning, as for the access permissions parameter in the open(2) or creat(2) system calls (though the execute permissions are not used by the system, and write permissions, for a semaphore set, effectively means alter permissions). Furthermore, while creating, the system call initializes the system semaphore set data structure __semid_ds__ as follows: __sem_perm.cuid__ and __sem_perm.uid__ are set to the effective user-ID of the calling process. __sem_perm.cgid__ and __sem_perm.gid__ are set to the effective group-ID of the calling process. The lowest order 9 bits of __sem_perm.mode__ are set to the lowest order 9 bit of ''semflg''. __sem_nsems__ is set to the value of ''nsems''. __sem_otime__ is set to 0. __sem_ctime__ is set to the current time. The argument ''nsems'' can be __0__ (a don't care) when the system call isn't a create one. Otherwise ''nsems'' must be greater than __0__ and less or equal to the maximum number of semaphores per semid, (__SEMMSL__). If the semaphore set already exists, the access permissions are verified, and a check is made to see if it is marked for destruction. !!RETURN VALUE If successful, the return value will be the semaphore set identifier (a positive integer), otherwise __-1__ with __errno__ indicating the error. !!ERRORS For a failing return, __errno__ will be set to one among the following values: __EACCES__ A semaphore set exists for ''key'', but the calling process has no access permissions to the set. __EEXIST__ A semaphore set exists for __key__ and ''semflg'' was asserting both __IPC_CREAT__ and __IPC_EXCL__. __EIDRM__ The semaphore set is marked as to be deleted. __ENOENT__ No semaphore set exists for ''key'' and ''semflg'' wasn't asserting __IPC_CREAT__. __ENOMEM__ A semaphore set has to be created but the system has not enough memory for the new data structure. __ENOSPC__ A semaphore set has to be created but the system limit for the maximum number of semaphore sets (__SEMMNI__), or the system wide maximum number of semaphores (__SEMMNS__), would be exceeded. !!NOTES __IPC_PRIVATE__ isn't a flag field but a __key_t__ type. If this special value is used for ''key'', the system call ignores everything but the lowest order 9 bits of ''semflg'' and creates a new semaphore set (on success). The followings are limits on semaphore set resources affecting a __semget__ call: __SEMMNI__ System wide maximum number of semaphore sets: policy dependent. __SEMMSL__ Maximum number of semaphores per semid: implementation dependent (500 currently). __SEMMNS__ System wide maximum number of semaphores: policy dependent. Values greater than __SEMMSL * SEMMNI__ makes it irrelevant. !!BUGS Use of __IPC_PRIVATE__ doesn't inhibit to other processes the access to the allocated semaphore set. As for the files, there is currently no intrinsic way for a process to ensure exclusive access to a semaphore set. Asserting both __IPC_CREAT__ and __IPC_EXCL__ in ''semflg'' only ensures (on success) that a new semaphore set will be created, it doesn't imply exclusive access to the semaphore set. The data structure associated with each semaphore in the set isn't initialized by the system call. In order to initialize those data structures, one has to execute a subsequent call to semctl(2) to perform a __SETVAL__ or a __SETALL__ command on the semaphore set. !!CONFORMING TO SVr4, SVID. SVr4 documents additional error conditions EINVAL, EFBIG, E2BIG, EAGAIN, ERANGE, EFAULT. !!SEE ALSO ftok(3), ipc(5), semctl(2), semop(2) ----
5 pages link to
semget(2)
:
ipc(2)
Man2s
ftok(3)
ipc(5)
semop(2)
This page is a man page (or other imported legacy content). We are unable to automatically determine the license status of this page.