Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ sem_open(2) — DG/UX 5.4R3.00

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

sysconf(2)



sem_open(2)                    DG/UX 5.4R3.00                    sem_open(2)


NAME
       semopen - create or access a named semaphore

SYNOPSIS
       #include <semaphore.h>

       semt *semopen (*name, oflag, protectionmode, value)
            char           *name;
            int            oflag;
            int            protectionmode;
            unsigned int   value;

   where:
       name            A null-terminated string naming the semaphore.
       oflag           Open intent and open behavior flags.
       protectionmode The standard nine permission bits.  This parameter is
                       only used when the semaphore is created.
       value           The initial value to assign to the semaphore.  This
                       parameter is only used when the semaphore is created.

DESCRIPTION
       Use semopen(2) to create or attach to a named semaphore.

       The semopen(2) function establishes a connection between a named
       semaphore and a process.  Following a successful call to semopen(2),
       the process may reference the semaphore associated with name by using
       the address returned from the call.  This address may be used in
       subsequent calls to semwait(2), semtrywait(2), and sempost(2).

       The name argument points to a string naming the semaphore.  The name
       of the semaphore appears in the filesystem, and is visible to
       functions that take pathnames as arguments.  As such, the name
       argument must conform to the construction rules for a pathname.  If
       name does not begin with a slash, the associated pathname is located
       relative to the current working directory of the opening process.

       After the semaphore named name has been created by semopen(2), other
       processes can connect to the semaphore by calling semopen(2) with
       the same value of name.  If name does not begin with a slash, other
       processes must take care to have the associated pathname resolve to
       the desired filesystem location.

       Once the semaphore has been successfully opened, the semaphore
       remains usable by the process until the semaphore is closed by a
       successful call to semclose(2), exit(2), or exec(2).  Semaphores are
       inherited on a fork(2).

       The oflag argument controls whether the semaphore is created or
       merely accessed by the call to semopen(2).  The semantics of the
       oflag follow the same rules as in the open(2) system call.  Namely,
       O_CREAT will access the semaphore, first creating it if it does not
       already exist.  O_CREAT | O_EXCL will create the semaphore only if it
       does not already exist.  The semaphore must be created with read and
       write intent allowed.



Licensed material--property of copyright holder(s)                         1




sem_open(2)                    DG/UX 5.4R3.00                    sem_open(2)


       When a new named semaphore is created, its user ID and group ID are
       set to the effective user ID and group ID of the creating process.
       The semaphore's permission bits are set to the value of the mode
       argument, except those set in the file mode creation mask of the
       process.  These permission bits and owner IDs are checked each time a
       process attempts to attach to the semaphore.

       The value specified with this call affects the availability of the
       semaphore. A successful lock operation, with semwait(2) or
       semtrywait(2), decrements the value and sempost(2) increments it.
       If the value is 0, the semaphore is unavailable.  In this case,
       semwait(2) blocks until the semaphore becomes available whereas
       semtrywait(2) returns with an error. Typical initial values
       specified with semopen(2) are 0 or 1.

       A named semaphore remains in the system until it is rebooted, or
       until both of the following occur:

        * A process that knows the semaphore's name calls semunlink(2).
          (The process need not be attached to the semaphore.)

        * All processes attached to the semaphore call semclose(2),
          exit(2), or exec(2).

       A process may have at most SEM_NSEMS_MAX named semaphores open at
       once. Use sysconf(2) with argument _SC_SEM_NSEMS_MAX to get this
       system value.

   Note
        * This routine is based on POSIX realtime extension document P1003.4
          draft 14. It is therefore subject to change.

        * Compilation of a source file using this routine requires that
          feature macro _POSIX4_DRAFT_SOURCE be defined.  This feature macro
          is not enabled by any other feature macro, nor does it enable any
          other feature macro.

        * The compiled routine must be linked to library librte.a.

RETURN VALUE
       If successful, semopen returns the address of the semaphore.  If
       unsuccessful, it returns -1 and sets ERRNO to one of the following:

        EACCES Permission to create or access the semaphore is denied.

        EEXIST O_CREAT and O_EXCL are set, but the semaphore already exists.

        EFAULT Unable to access one of the parameters.

        EINTR  The semopen(2) operation was interrupted by a signal.

        EINVAL Unable to create the semaphore.

        EINVAL name, or value, is not valid.



Licensed material--property of copyright holder(s)                         2




sem_open(2)                    DG/UX 5.4R3.00                    sem_open(2)


        EMFILE Too many semaphores are currently in use by this process.

        ENAMETOOLONG
               name contains more than NAME_MAX characters.

        ENOENT sem does not exist and oflag does not have O_CREAT set.

        ENOSPC The calling process already has SEM_NSEMS_MAX named
               semaphores open.

        ENOSPC There is insufficient space for the creation of the new named
               semaphore.

SEE ALSO
       semclose(2), semwait(2), semtrywait(2), sempost(2),
       semunlink(2), seminit(2), sysconf(2).









































Licensed material--property of copyright holder(s)                         3


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