


SEMGET(2)                 SYSTEM CALLS                  SEMGET(2)



NAME
     semget - get set of semaphores

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

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

DESCRIPTION
     semget() returns the semaphore  identifier  associated  with
     _k_e_y.

     A semaphore identifier and associated data structure and set
     containing  _n_s_e_m_s  semaphores (see intro(2)) are created for
     _k_e_y if one of the following are true:

     o+  _k_e_y is equal to IPC_PRIVATE.

     o+  _k_e_y does not already have a semaphore identifier  associ-
        ated with it, and (_s_e_m_f_l_g & IPC_CREAT) is ``true''.

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

     o+  sem_perm.cuid,    sem_perm.uid,    sem_perm.cgid,     and
        sem_perm.gid  are  set equal to the effective user ID and
        effective group ID, respectively, of the calling process.

     o+  The low-order 9 bits of sem_perm.mode are  set  equal  to
        the low-order 9 bits of _s_e_m_f_l_g.

     o+  sem_nsems is set equal to the value of _n_s_e_m_s.

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

     A semaphore identifier (semid) is a unique positive  integer
     created by a semget(2) system call.  Each semid has a set of
     semaphores and a data structure  associated  with  it.   The
     data  structure  is referred to as semid_ds and contains the
     following members:

          struct  ipc_perm sem_perm;  /* operation permission struct */
          ushort  sem_nsems;          /* number of sems in set */
          time_t  sem_otime;          /* last operation time */
          time_t  sem_ctime;          /* last change time */
                                      /* Times measured in secs since */
                                      /* 00:00:00 GMT, Jan. 1, 1970 */



Sun Release 4.1   Last change: 21 January 1990                  1






SEMGET(2)                 SYSTEM CALLS                  SEMGET(2)



     sem_perm is an ipc_perm structure that specifies  the  sema-
     phore  operation  permission  (see  below).   This structure
     includes the following members:

          ushort  cuid;               /* creator user id */
          ushort  cgid;               /* creator group id */
          ushort  uid;                /* user id */
          ushort  gid;                /* group id */
          ushort  mode;               /* r/a permission */

     The value of sem_nsems is equal to the number of  semaphores
     in  the  set.   Each semaphore in the set is referenced by a
     positive integer referred to as a sem_num.   sem_num  values
     run  sequentially  from 0 to the value of sem_nsems minus 1.
     sem_otime is the time of the last  semop(2)  operation,  and
     sem_ctime  is  the time of the last semctl(2) operation that
     changed a member of the above structure.

     A semaphore is a data structure that contains the  following
     members:

          ushort  semval;             /* semaphore value */
          short   sempid;             /* pid of last operation  */
          ushort  semncnt;            /* # awaiting semval > cval */
          ushort  semzcnt;            /* # awaiting semval = 0 */

     semval is a non-negative integer.  sempid is  equal  to  the
     process  ID  of  the last process that performed a semaphore
     operation on this semaphore.  semncnt  is  a  count  of  the
     number  of  processes  that are currently suspended awaiting
     this semaphore's semval to become greater than  its  current
     value.   semzcnt  is a count of the number of processes that
     are currently suspended awaiting this semaphore's semval  to
     become zero.

RETURN VALUES
     semget() returns a non-negative semaphore identifier on suc-
     cess.   On failure, it returns -1 and sets errno to indicate
     the error.

ERRORS
     EACCES         A semaphore identifier exists  for  _k_e_y,  but
                    operation permission (see intro(2)) as speci-
                    fied by the low-order 9 bits of _s_e_m_f_l_g  would
                    not be granted.

     EEXIST         A semaphore identifier exists for _k_e_y  but  (
                    (_s_e_m_f_l_g & IPC_CREAT) and (_s_e_m_f_l_g & IPC_EXCL))
                    is ``true''.

     EINVAL         _n_s_e_m_s is either less than or equal to zero or
                    greater than the system-imposed limit.



Sun Release 4.1   Last change: 21 January 1990                  2






SEMGET(2)                 SYSTEM CALLS                  SEMGET(2)



                    A semaphore identifier exists  for  _k_e_y,  but
                    the  number  of semaphores in the set associ-
                    ated with it is less than _n_s_e_m_s and _n_s_e_m_s  is
                    not equal to zero.

     ENOENT         A semaphore identifier does not exist for _k_e_y
                    and (_s_e_m_f_l_g & IPC_CREAT) is ``false''.

     ENOSPC         A semaphore identifier is to be  created  but
                    the   system-imposed  limit  on  the  maximum
                    number of allowed semaphore identifiers  sys-
                    tem wide would be exceeded.

                    A semaphore identifier is to be  created  but
                    the   system-imposed  limit  on  the  maximum
                    number  of  allowed  semaphores  system  wide
                    would be exceeded.

SEE ALSO
     ipcrm(1), ipcs(1), intro(2), semctl(2), semop(2)



































Sun Release 4.1   Last change: 21 January 1990                  3



