---
name: "mq_close"
section: "3"
platform: "linux"
package: "man-pages"
version: "6.19-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/mq_close/3"
---

# mq\_close(3)

close a message queue descriptor

## NAME

mq\_close - close a message queue descriptor

## LIBRARY

Real-time library (*librt*, *-lrt*)

## SYNOPSIS

```
#include <mqueue.h>
```

**int mq\_close(mqd\_t** *mqdes***);**

## DESCRIPTION

**mq\_close**() closes the message queue descriptor *mqdes*.

If the calling process has attached a notification request (see [**mq\_notify**(3)](/mq_notify/3.md)) to this message queue via *mqdes*, then this request is removed, and another process can now attach a notification request.

## RETURN VALUE

On success **mq\_close**() returns 0; on error, -1 is returned, with *errno* set to indicate the error.

## ERRORS

- **EBADF**

  The message queue descriptor specified in *mqdes* is invalid.

## ATTRIBUTES

For an explanation of the terms used in this section, see [**attributes**(7)](/attributes/7.md).

| | | |
| --- | --- | --- |
| **Interface** | **Attribute** | **Value** |
| **mq\_close**() | Thread safety | MT-Safe |

## STANDARDS

POSIX.1-2008.

## HISTORY

POSIX.1-2001.

## NOTES

All open message queues are automatically closed on process termination, or upon [**execve**(2)](/execve/2.md).

## SEE ALSO

[**mq\_getattr**(3)](/mq_getattr/3.md), [**mq\_notify**(3)](/mq_notify/3.md), [**mq\_open**(3)](/mq_open/3.md), [**mq\_receive**(3)](/mq_receive/3.md), [**mq\_send**(3)](/mq_send/3.md), [**mq\_unlink**(3)](/mq_unlink/3.md), [**mq\_overview**(7)](/mq_overview/7.md)
