sem_unlink()--Unlink Named Semaphore


  Syntax
 #include <semaphore.h>

 int sem_unlink(const char *name);  

  Service Program Name: QP0ZPSEM

  Default Public Authority: *USE

  Threadsafe: Yes

The sem_unlink() function unlinks a named semaphore. The name of the semaphore is removed from the set of names used by named semaphores. If the semaphore is still in use, the semaphore is not deleted until all processes using the semaphore have ended or have called sem_close(). Using the name of an unlinked semaphore in subsequent calls to sem_open() or sem_open_np() will result in the creation of a new semaphore with the same name if the O_CREAT flag of the oflag parameter has been set.


Parameters

name
(Input) A pointer to the null-terminated name of the semaphore to be unlinked. The name should begin with a slash ('/') character. If the name does not begin with a slash ('/') character, the system adds a slash to the beginning of the name.

This parameter is assumed to be represented in the coded character set identifier (CCSID) currently in effect for the job. If the CCSID of the job is 65535, this parameter is assumed to be represented in the default CCSID of the job.

The name is present in a set of names used only by named semaphores. The name has no relation to any file system path names. The maximum length of the name is SEM_NAME_MAX.

See QlgSem_unlink()--Unlink Named Semaphore (using NLS-enabled path name) for a description and an example of supplying the name in any CCSID.


Authorities

Authorization required for sem_unlink()

Object Referred to Authority Required errno
Named semaphore to be deleted See note EACCES

Note: To unlink a named semaphore, the effective UID of the process must be the creator of the semaphore or the process must have *ALLOBJ authority.


Return Value

0 sem_unlink() was successful.
-1 sem_unlink() was not successful. The errno variable is set to indicate the error.


Error Conditions

If sem_unlink() is not successful, errno usually indicates one of the following errors. Under some conditions, errno could indicate an error other than those listed here.

[EACCES]

Permission denied.

An attempt was made to access an object in a way forbidden by its object access permissions.

[ENOENT]

No such path or directory.

The specified name doesnot refer to an existing named semaphore.

[EFAULT]

The address used for an argument is not correct.

In attempting to use an argument in a call, the system detected an address that is not valid.

While attempting to access a parameter passed to this function, the system detected an address that is not valid.

[ENAMETOOLONG]

The name is too long. The name is longer than the SEM_NAME_MAX characters.


Error Messages

None.


Related Information


Example

See Code disclaimer information for information pertaining to code examples.

The following example unlinks the named semaphore "/mysem".

#include <semaphore.h>
main() {
  int rc;

  rc = sem_unlink("/mysem");

}


API introduced: V4R4
Top | UNIX-Type APIs | APIs by category