icon Top 9 categories map      RocketAware > man pages >

semctl(2)

Tips: Browse or Search all pages for efficient awareness of more than 6000 of the most popular reusable and open source applications, functions, libraries, and FAQs.


The "RKT couplings" below include links to source code, updates, additional information, advice, FAQs, and overviews.


Home

Search all pages


Subjects

By activity
Professions, Sciences, Humanities, Business, ...

User Interface
Text-based, GUI, Audio, Video, Keyboards, Mouse, Images,...

Text Strings
Conversions, tests, processing, manipulation,...

Math
Integer, Floating point, Matrix, Statistics, Boolean, ...

Processing
Algorithms, Memory, Process control, Debugging, ...

Stored Data
Data storage, Integrity, Encryption, Compression, ...

Communications
Networks, protocols, Interprocess, Remote, Client Server, ...

Hard World
Timing, Calendar and Clock, Audio, Video, Printer, Controls...

File System
Management, Filtering, File & Directory access, Viewers, ...

    

RocketLink!--> Man page versions: OpenBSD FreeBSD NetBSD RedHat Solaris Others



SEMCTL(2)                 OpenBSD Programmer's Manual                SEMCTL(2)

NAME
     semctl - semaphore control operations



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

     int
     semctl(int semid, int semnum, int cmd, union semun arg);

DESCRIPTION
     The semctl() system call provides a number of control operations on the
     semaphore specified by semnum and semid. The operation to be performed is
     specified in cmd (see below).  arg is a union of the following fields:

             int     val;                    /* value for SETVAL */
             struct  semid_ds *buf;          /* buffer for IPC_{STAT,SET} */
             u_short *array;                 /* array for GETALL & SETALL */

     The semid_ds  structure used in the IPC_SET and IPC_STAT commands is de-
     fined as follows in <sys/sem.h>:

     struct semid_ds {
             struct ipc_perm sem_perm;       /* operation permissions */
             struct  sem *sem_base;          /* semaphore set */
             u_short sem_nsems;              /* number of sems in set */
             time_t  sem_otime;              /* last operation time */
             time_t  sem_ctime;              /* last change time */
     };

     The ipc_perm  structure used inside the semid_ds  structure is defined in
     <sys/ipc.h> and looks like this:

     struct ipc_perm {
             uid_t   cuid;           /* creator user id */
             gid_t   cgid;           /* creator group id */
             uid_t   uid;            /* user id */
             gid_t   gid;            /* group id */
             mode_t  mode;           /* r/w permission (see chmod(2)) */
             u_short seq;            /* sequence # (to generate unique msg/sem/shm id) */
             key_t key;              /* user specified msg/sem/shm key */
     };

     semctl() provides the following operations:

     GETVAL     Return the value of the semaphore.

     SETVAL     Set the value of the semaphore to arg.val.

     GETPID     Return the pid of the last process that did an operation on
                this semaphore.

     GETNCNT    Return the number of processes waiting to acquire the
                semaphore.

     GETZCNT    Return the number of processes waiting for the value of the
                semaphore to reach 0.

     GETALL     Return the values for all the semaphores associated with
                semid.

     SETALL     Set the values for all the semaphores that are associated with
                the semaphore identifier semid to the corresponding values in
                arg.array.

     IPC_STAT   Gather statistics about a semaphore and place the information
                in the semid_ds  structure pointed to by arg.buf (see above).

     IPC_SET    Set the value of the sem_perm.uid, sem_perm.gid and
                sem_perm.mode fields in the structure associated with the
                semaphore.  The values are taken from the corresponding fields
                in the structure pointed to by arg.buf. This operation can on-
                ly be executed by the super-user, or a process that has an ef-
                fective user ID equal to either sem_perm.cuid or sem_perm.uid
                in the data structure associated with the message queue.

     IPC_RMID   Remove the semaphores associated with semid from the system
                and destroy the data structures associated with it. Only the
                super-user or a process with an effective UID equal to the
                sem_perm.cuid or sem_perm.uid values in the data structure as-
                sociated with the semaphore can do this.

     The permission to read or change a message queue (see semop(2))  is de-
     termined by the sem_perm.mode field in the same way as is done with files
     (see chmod(2)),  but the effective UID can match either the sem_perm.cuid
     field or the sem_perm.uid field, and the effective GID can match either
     sem_perm.cgid or sem_perm.gid.

RETURN VALUES
     For the GETVAL, GETPID, GETNCNT, and GETZCNT operations, semctl() returns
     one of the values described above if successful. All other operations
     will make semctl() return 0 if no errors occur. Otherwise -1 is returned
     and errno set to reflect the error.

ERRORS
     semctl() will fail if:

     [EPERM]       cmd is equal to IPC_SET or IPC_RMID and the caller is not
                   the super-user, nor does the effective UID match either the
                   sem_perm.uid or sem_perm.cuid fields of the data structure
                   associated with the message queue.

     [EACCES]      The caller has no operation permission for this semaphore.

     [EINVAL]      semid is not a valid message semaphore identifier.

                   cmd is not a valid command.

     [EFAULT]      arg.buf specifies an invalid address.

SEE ALSO
     semget(2),  semop(2)

OpenBSD 2.6                     August 17, 1995                              2

Source: OpenBSD 2.6 man pages. Copyright: Portions are copyrighted by BERKELEY
SOFTWARE DESIGN, INC., The Regents of the University of California, Massachusetts
Institute of Technology, Free Software Foundation, FreeBSD Inc., and others.



(Corrections, notes, and links courtesy of RocketAware.com)


[Detailed Topics]


[Overview Topics]

Up to: Local Process Communication - Communication between processes running on the same system. Synchronization. File locking. Signals. FIFOs, pipes, et al
Up to: Process Signals and Events - Sending and handling signals and events.


RocketLink!--> Man page versions: OpenBSD FreeBSD NetBSD RedHat Solaris Others






Rapid-Links: Search | About | Comments | Submit Path: RocketAware > man pages > semctl.2/
RocketAware.com is a service of Mib Software
Copyright 1999, Forrest J. Cavalier III. All Rights Reserved.
We welcome submissions and comments