---
name: "mq_unlink"
section: "2"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["linux", "freebsd"]
url: "https://new.carta.tech/mq_unlink"
---

# mq\_unlink(2)

mq\_unlink - remove a message queue (REALTIME)

## NAME

**mq\_unlink** – mq\_unlink - remove a message queue (REALTIME)

## LIBRARY

library “librt”

## SYNOPSIS

**#include \<mqueue.h\>**

*int*\

**mq\_unlink**(*const char \*name*);

## DESCRIPTION

The **mq\_unlink**() function removes the message queue named by the string *name*. If one or more processes have the message queue open when **mq\_unlink**() is called, destruction of the message queue will be postponed until all references to the message queue have been closed. However, the **mq\_unlink**() call need not block until all references have been closed; it may return immediately.

After a successful call to **mq\_unlink**(), reuse of the name will subsequently cause [mq\_open(2)](/mq_open/2.md) to behave as if no message queue of this name exists.

## RETURN VALUES

The **mq\_unlink()** function returns the value 0 if successful; otherwise the value -1 is returned and the global variable errno is set to indicate the error.

## ERRORS

The **mq\_unlink**() system call will fail if:

- \[EACCESS\]

  Permission is denied to unlink the message queue represented by *name*.

- \[EINVAL\]

  *name* is invalid.

- \[ENAMETOOLONG\]

  The length of the *name* argument exceeds {PATH\_MAX} or a pathname component is longer than {NAME\_MAX}.

- \[ENOENT\]

  The message queue does not exist.

- \[ENOSYS\]

  [mqueuefs(4)](/mqueuefs/4.md) module is neither loaded nor included in the kernel.

## SEE ALSO

[mq\_open(2)](/mq_open/2.md)

## STANDARDS

The **mq\_unlink**() system call conforms to IEEE Std 1003.1-2004 (“POSIX.1”). The \[EACCESS\] error code is an extension to the standard.

## HISTORY

Support for POSIX message queues first appeared in FreeBSD 7.0.

## COPYRIGHT

Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.
