shm_unlink()

Updated: May 06, 2022

Remove the name of a shared memory object

Synopsis:

#include <sys/mman.h>

int shm_unlink( const char * name );

Arguments:

name
The name of the shared memory object that you want to remove.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The shm_unlink() function removes the name of the shared memory object specified by name. After removing the name, you can't use shm_open() to access the object.

This function doesn't affect any references to the shared memory object (i.e., file descriptors or memory mappings). The reference count is on the underlying object; there's no reference count on the name. The name counts as one of the references, so the reference count is decremented by this function, but the shared memory isn't actually deleted until you remove all open and mmap references to it.

Returns:

0
Success.
-1
An error occurred (errno is set).

Errors:

EACCES
Permission to unlink the shared memory object is denied.
ELOOP
Too many levels of symbolic links or prefixes.
ENAMETOOLONG
The length of the name argument exceeds NAME_MAX.
ENOENT
The named shared memory object doesn't exist, or the name argument points to an empty string.
ENOSYS
The shm_unlink() function isn't supported by this implementation.

Examples:

See shm_open().

Classification:

POSIX 1003.1 SHM

Safety:  
Cancellation point No
Interrupt handler No
Signal handler Yes
Thread Yes