Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

semget(2)

semop(2)

semctl(2)                                                         semctl(2)

NAME
     semctl - semaphore control functions

SYNOPSIS
     #include <sys/sem.h>

     int semctl(int semid, int semnum, int cmd, ... );

DESCRIPTION
     semctl() provides a variety of semaphore control operations as speci-
     fied by cmd.

     The following commands can be issued as the cmd. These commands relate
     to the semaphore specified by semid and semnum:

     GETVAL     Return the value of semval.

     SETVAL     Set semval to the value of the fourth argument (int). When
                this command is successfully executed, the semadj value
                corresponding to the specified semaphore in all processes
                is cleared.

     GETPID     Return the value of (int) sempid.

     GETNCNT    Return the value of semncnt.

     GETZCNT    Return the value of semzcnt.

     The following commands return and set, respectively, every semval in
     the set of semaphores.

     GETALL     Return semval and place into the array of type unsigned
                short pointed to by the fourth argument to semctl().
                Requires read permission.

     SETALL     Set semval according to the array of type unsigned short
                pointed to by the fourth argument to semctl(). When this
                command is successfully executed, the semadj values corre-
                sponding to each specified semaphore in all processes are
                cleared. Requires write permission.

     The following commands are also available:

     IPCSTAT   Place the current value of each member of the semidds data
                structure associated with semid into the semidds structure
                pointed to by the fourth argument of semctl().









Page 1                       Reliant UNIX 5.44                Printed 11/98

semctl(2)                                                         semctl(2)

     IPCSET    Set the value of the following members of the semidds data
                structure associated with semid to the corresponding value
                found in the semidds structure pointed to by the fourth
                argument of semctl().

                semperm.uid
                semperm.gid
                semperm.mode /* only access permission bits */

                This command can be executed only by a process that has an
                effective user ID equal to either that of superuser, or to
                the value of semperm.cuid or semperm.uid in the data
                structure associated with semid.

     IPCRMID   Remove the semaphore identifier specified by semid from the
                system and destroy the set of semaphores and data structure
                associated with it. This command can only be executed by a
                process that has an effective user ID equal to either that
                of superuser, or to the value of semperm.cuid or
                semperm.uid in the data structure associated with semid.

     semctl() fails if one or more of the following apply:

     EACCES     Operation permission is denied to the calling process.

     EINVAL     semid is not a valid semaphore identifier.

     EINVAL     semnum is less than 0 or greater than semnsems.

     EINVAL     cmd is not a valid command.

     EINVAL     cmd is IPCSET and semperm.uid or semperm.gid is not
                valid.

     EOVERFLOW  cmd is IPCSTAT and uid or gid is too large to be stored in
                the structure pointed to by the fourth argument of
                semctl().

     ERANGE     cmd is SETVAL or SETALL and the value to which semval is to
                be set is greater than the system imposed maximum.

     EPERM      cmd is equal to IPCRMID or IPCSET and the effective user
                ID of the calling process is not equal to that of
                superuser, or to the value of semperm.cuid or semperm.uid
                in the data structure associated with semid.

     EFAULT     The fourth argument points to an illegal address.







Page 2                       Reliant UNIX 5.44                Printed 11/98

semctl(2)                                                         semctl(2)

RESULT
     Upon successful completion, the value returned depends on cmd as fol-
     lows:

     GETVAL     The value of semval

     GETPID     The value of (int) sempid

     GETNCNT    The value of semncnt

     GETZCNT    The value of semzcnt

     All others A value of 0

     Otherwise, a value of -1 is returned and errno is set to indicate the
     error.

NOTES
     The fourth argument of the semctl() call can be defined as follows:

     union semun {
        long val;
        struct semidds *buf;
        unsigned short *array;
     } arg;

     In the future there may be modifications to the interfaces for inter-
     process communication. You should design your applications so that in
     modules using semctl() this function can easily be replaced by others.

SEE ALSO
     semget(2), semop(2).






















Page 3                       Reliant UNIX 5.44                Printed 11/98

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