Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ semget(3) — AIX PS/2 1.2.1

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

semctl

semop

stdipc: ftok



SEMGET(3,L)                 AIX Technical Reference                 SEMGET(3,L)



-------------------------------------------------------------------------------
semget



PURPOSE

Gets a set of semaphores.

LIBRARY

Standard C Library (libc.a)

SYNTAX

#include <sys/stat.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/sem.h>

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

DESCRIPTION

The semget system call returns the semaphore identifier associated with the
specified key.  The key parameter is either the value IPC_PRIVATE or an IPC key
constructed by the ftok subroutine (or by a similar algorithm).  See "stdipc:
ftok" for details about this subroutine.  The nsems parameter specifies the
number of semaphores in the set.

The semflg parameter is constructed by logically ORing one or more of the
following values:

IPC_CREAT    Creates the data structure if it does not already exist.
IPC_EXCL     Causes the semget system call to fail if IPC_CREAT is also set and
             the data structure already exists.
S_IRUSR      Permits the process that owns the data structure to read it.
S_IWUSR      Permits the process that owns the data structure to modify it.
S_IRGRP      Permits the group associated with the data structure to read it.
S_IWGRP      Permits the group associated with the data structure to modify it.
S_IROTH      Permits others to read the data structure.
S_IWOTH      Permits others to modify the data structure.

The values that begin with S_I- are defined in the sys/stat.h header file and
are a subset of the access permissions that apply to files.

The semget system call creates a data structure for the semaphore ID and an
array containing nsems semaphores if one of the following is true:

  o The key parameter is equal to IPC_PRIVATE.



Processed November 7, 1990        SEMGET(3,L)                                 1





SEMGET(3,L)                 AIX Technical Reference                 SEMGET(3,L)




  o The key parameter does not already have a semaphore identifier associated
    with it, and IPC_CREAT is set.

Upon creation, the data structure associated with the new semaphore identifier
is initialized as follows:

  o sem_perm.cuid and sem_perm.uid are set equal to the effective user ID of
    the calling process.

  o sem_perm.cgid and sem_perm.gid are set equal to the effective group ID of
    the calling process.

  o The low-order nine bits of sem_perm.mode are set equal to the low-order
    nine bits of the semflg parameter.

  o sem_nsems is set equal to the value of the nsems parameter.

  o sem_otime is set equal to 0 and sem_ctime is set equal to the current time.

If the key parameter is not IPC_PRIVATE, IPC_EXCL is not set, and a semaphore
identifier already exists for the specified key, then the value of the nsems
parameter specifies the number of semaphores that the current process needs.
If the nsems parameter is 0, then any number of semaphores is acceptable.  If
the nsems parameter is not 0, then the semget system call fails if the set
contains fewer than nsems semaphores.

Note:  In a Transparent Computing Facility cluster, semaphores are not
       maintained across the cluster.  This means that a process cannot
       communicate via semaphores to processes on another cluster site and the
       process itself cannot migrate.

RETURN VALUE

Upon successful completion, a semaphore identifier is returned.  If semget
fails, a value of -1 is returned and errno is set to indicate the error.

ERROR CONDITIONS

The semget system call fails if one or more of the following are true:

EINVAL  The nsems parameter is less than 0, equal to 0, or greater than the
        system-imposed limit.

EACCES  A semaphore identifier exists for the key parameter but operation
        permission, as specified by the low-order nine bits of the semflg
        parameter, is not granted.

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




Processed November 7, 1990        SEMGET(3,L)                                 2





SEMGET(3,L)                 AIX Technical Reference                 SEMGET(3,L)



ENOENT  A semaphore identifier does not exist for the key parameter and
        IPC_CREAT is not set.

ENOSPC  A semaphore identifier is to be created, but doing so would exceed the
        maximum number of identifiers allowed system wide.

EEXIST  A semaphore identifier exists for the key parameter, and both IPC_CREAT
        and IPC_EXCL are set.

EAGAIN  Cannot allocate space for a semaphore data structure.

RELATED INFORMATION

In this book:  "semctl," "semop," and "stdipc: ftok."









































Processed November 7, 1990        SEMGET(3,L)                                 3



Typewritten Software • bear@typewritten.org • Edmonds, WA 98026