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

# mq\_getfd\_np(3)

get a file descriptor for an open message queue descriptor

## NAME

**mq\_getfd\_np** – get a file descriptor for an open message queue descriptor

## SYNOPSIS

library “librt”

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

*int*\

**mq\_getfd\_np**(*mqd\_t mqd*);

## DESCRIPTION

The **mq\_getfd\_np** function retrieves the underlying file descriptor from the given message queue descriptor returned from [mq\_open(2)](/mq_open/2.md). The file descriptor is used by other functions to refer to that message queue. The *mqd* argument must be an open message queue descriptor.

## IMPLEMENTATION NOTES

FreeBSD implements retrieval or alteration of message queue attributes based on the file descriptor. The open file descriptor is copied into a child after [fork(2)](/fork/2.md). The [fstat(2)](/fstat/2.md), [fchmod(2)](/fchmod/2.md), and [fchown(2)](/fchown/2.md) system calls are supported for the file descriptor.

The file descriptor is safe to use so long as the message queue descriptor remains open.

## RETURN VALUES

Upon successful completion, the function returns a file descriptor.

## ERRORS

The **mq\_getfd\_np** function does not return any errors.

## SEE ALSO

[mq\_close(2)](/mq_close/2.md), [mq\_open(2)](/mq_open/2.md), [mqueuefs(4)](/mqueuefs/4.md)

## HISTORY

Support for the **mq\_getfd\_np** function first appeared in FreeBSD 11.0.
