Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
HP-UX Reference > S


HP-UX 11i Version 3: February 2007

Technical documentation

» Feedback
Content starts here

 » Table of Contents

 » Index


sem_unlink — unlink a named POSIX semaphore


#include <sys/semaphore.h>

int sem_unlink(const char *name);


sem_unlink() is used to unlink named semaphores. A successful call to sem_unlink() marks the semaphore, specified by name, for removal. Calling sem_unlink() does not affect processes, including the calling process, which currently have a descriptor, obtained from a call to sem_open(). Named semaphores are uniquely identified by character strings. All character string names will be pre-processed to ensure variations of a pathname resolve to the same semaphore name. If the semaphore is successfully marked for removal by a call to sem_unlink(), the semaphore will be removed when all processes remove their descriptors to the specified semaphore by calling sem_close(). Subsequent calls to sem_open() using the string name will refer to a new semaphore.

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


The following call to sem_unlink() will remove the named semaphore named by the string name. If the semaphore is currently referenced by one or more processes, the semaphore will be marked for removal and removed when there are no more processes referencing it.



If the semaphore was unlinked successfully, sem_unlink() returns 0.

If the semaphore could not be unlinked, the call returns -1 and sets errno to indicate the error.


sem_unlink() fails and does not perform the requested operation if any of the following conditions are encountered:


The named semaphore exists and the process does not have the permissions to unlink the semaphore.


The name string is longer than {PATH_MAX}.


The flag O_CREAT is not set in oflag (see sem_open(2)) and the named semaphore does not exist.


sem_close(2), sem_open(2), privileges(5), <semaphore.h>.


sem_unlink(): POSIX

Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© 1983-2007 Hewlett-Packard Development Company, L.P.