*nix Documentation Project
·  Home
 +   man pages
·  Linux HOWTOs
·  FreeBSD Tips
·  *niX Forums

  man pages->HP-UX 11i man pages -> sem_open (2)              


 sem_open(2)                                                     sem_open(2)

 NAME    [Toc]    [Back]
      sem_open - create/open a named POSIX semaphore

 SYNOPSIS    [Toc]    [Back]
      #include <sys/semaphore.h>

      sem_t * sem_open(const char *name, int oflag, mode_t mode,
           unsigned int value);

 DESCRIPTION    [Toc]    [Back]
      sem_open() is used to open or create a named semaphore.  A successful
      call to sem_open() will create a descriptor for the semaphore
      specified by name.  The pointer to the semaphore returned by
      sem_open() can be used to access the semaphore associated with name in
      subsequent operations.  The name argument points to a string referring
      to a semaphore. It should begin with a "/" and shall conform to
      pathname rules except that no path component should be "." or "..".

      The oflag argument specifies whether a semaphore is to be created or
      not.  The following bits in it may be set:

           O_CREAT        If this flag is set, a new semaphore is created if
                          it does not already exist.  If this flag is not
                          set, the semaphore should already exist.

           O_EXCL         If this flag is set, the call fails if the
                          semaphore already exists.  This flag is valid only
                          when O_CREAT is also set; otherwise, it is

      The mode and value arguments are provided to supply the permissions
      and the initial value information necessary for creating a new

      To use this function, link in the realtime library by specifying -lrt
      on the compiler or linker command line.

 EXAMPLES    [Toc]    [Back]
      The following call to sem_open() will create a new named semaphore if
      one does not exist, which depends on the flags specified in oflag, has
      the permissions specified in mode and has an initial value of value.

           sem_open(name, oflag, mode, value);

 RETURN VALUE    [Toc]    [Back]
      If the semaphore was created and initialized, sem_open() returns a
      pointer to a sem_t structure containing the index of the new

      If the semaphore could not be created/initialized, the call returns -1
      and sets errno to indicate the error.  If the named semaphore is

 Hewlett-Packard Company            - 1 -   HP-UX 11i Version 2: August 2003

 sem_open(2)                                                     sem_open(2)

      already opened by the calling process, a descriptor and a sem_t
      structure for the named semaphore already exists for the calling
      process.  A new descriptor is not created and a pointer to the
      existing sem_t structure is returned for this call.

 ERRORS    [Toc]    [Back]
      sem_open() fails and does not perform the requested operation if any
      of the following conditions are encountered:

           [EACCES]       The named semaphore exists and the process does
                          not have the permissions to open the semaphore as
                          described by oflag, or the named semaphore does
                          not exist and the process does not have the
                          permission to open it.

           [EEXIST]       The flags O_CREAT and O_EXCL are set in oflag and
                          the named semaphore exists.

           [EINTR]        A signal interrupted the sem_open() operation.

           [EINVAL]       The argument value is greater than
                          {_POSIX_SEM_VALUE_MAX} and the O_CREAT flag was
                          specified in oflag.

           [EINVAL]       The name argument does not begin with "/" or
                          contains "." or ".." as a pathname component.

           [EMFILE]       Too many semaphore descriptors are currently in
                          use by this process.

           [ENAMETOOLONG] The name string is longer than {PATH_MAX}.

           [ENFILE]       There are too many semaphores in the system.

           [ENOENT]       The flag O_CREAT is not set in oflag and the named
                          semaphore does not exist.

           [ENOSPC]       There are insufficient resources for the creation
                          of a new named semaphore.

 SEE ALSO    [Toc]    [Back]
      sem_close(2), sem_post(2), sem_wait(2), sem_unlink(2), <semaphore.h>.

      sem_open(): POSIX

 Hewlett-Packard Company            - 2 -   HP-UX 11i Version 2: August 2003
[ Back ]
 Similar pages
Name OS Title
sem_open IRIX open a posix named semaphore
pipcrm HP-UX remove a POSIX message queue or a POSIX named semaphore
sem_unlink HP-UX unlink a named POSIX semaphore
sem_close IRIX close a posix named semaphore
sem_unlink IRIX deletes a posix named semaphore
sem_close HP-UX close a named POSIX semaphore
sem_getvalue IRIX get the value of a posix named or unnamed semaphore
sem_wait IRIX acquire a posix named or unnamed semaphore
sem_post IRIX release a posix named or unnamed semaphore
sem_getvalue HP-UX get the value of a POSIX semaphore
Copyright © 2004-2005 DeniX Solutions SRL
newsletter delivery service