*nix Documentation Project
·  Home
 +   man pages
·  Linux HOWTOs
·  FreeBSD Tips
·  *niX Forums

  man pages->NetBSD man pages -> semget (2)              



NAME    [Toc]    [Back]

     semget - get set of semaphores

LIBRARY    [Toc]    [Back]

     Standard C Library (libc, -lc)

SYNOPSIS    [Toc]    [Back]

     #include <sys/sem.h>

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

DESCRIPTION    [Toc]    [Back]

     The semget() system call returns the semaphore identifier associated with

     A new set containing nsems semaphores is created if either key is equal
     to IPC_PRIVATE, or key does not have a semaphore set associated with it
     and the IPC_CREAT bit is set in semflg.

     If a new set of semaphores is created, the data structure associated with
     it (the semid_ds structure, see semctl(2)) is initialized as follows:

     +o   sem_perm.cuid and sem_perm.uid are set to the effective uid of the
         calling process.

     +o   sem_perm.gid and sem_perm.cgid are set to the effective gid of the
         calling process.

     +o   sem_perm.mode is set to the lower 9 bits of semflg.

     +o   sem_nsems is set to the value of nsems.

     +o   sem_ctime is set to the current time.

     +o   sem_otime is set to 0.

RETURN VALUES    [Toc]    [Back]

     semget() returns a non-negative semaphore identifier if successful. Otherwise,
 -1 is returned and errno is set to reflect the error.

ERRORS    [Toc]    [Back]

     [EACCES]           The caller has no permission to access a semaphore set
                        already associated with key.

     [EEXIST]           Both IPC_CREAT and IPC_EXCL are set in semflg, and a
                        semaphore set is already associated with key.

     [EINVAL]           nsems is less than 0 or greater than the system limit
                        for the number in a semaphore set.

                        A semaphore set associated with key exists, but has
                        fewer semaphores than the number specified in nsems.

     [ENOSPC]           A new set of semaphores could not be created because
                        the system limit for the number of semaphores or the
                        number of semaphore sets has been reached.

     [ENOENT]           IPC_CREAT is not set in semflg and no semaphore set
                        associated with key was found.

SEE ALSO    [Toc]    [Back]

     semctl(2), semop(2), ftok(3)

STANDARDS    [Toc]    [Back]

     The semget system call conforms to X/Open System Interfaces and Headers
     Issue 5 (``XSH5'').

HISTORY    [Toc]    [Back]

     Semaphores appeared in the first release of AT&T System V UNIX.

BSD                             August 25, 1999                            BSD
[ Back ]
 Similar pages
Name OS Title
sem FreeBSD POSIX semaphores
semmsl HP-UX maximum number of System V IPC semaphores per identifier
lockf HP-UX provide semaphores and record locking on files
sema HP-UX enable or disable System V IPC semaphores at boot time
perlipc OpenBSD Perl interprocess communication (signals, fifos, pipes, safe subprocesses, sockets, and semaphores)
perlipc IRIX Perl interprocess communication (signals, fifos, pipes, safe subprocesses, sockets, and semaphores)
semmns HP-UX number of System V IPC system-wide semaphores
Copyright © 2004-2005 DeniX Solutions SRL
newsletter delivery service