---
name: "kinfo_getfile"
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/kinfo_getfile"
---

# kinfo\_getfile(3)

function for getting per-process file descriptor information

## NAME

**kinfo\_getfile** – function for getting per-process file descriptor information

## LIBRARY

System Utilities Library (libutil, -lutil)

## SYNOPSIS

**#include \<sys/types.h\>**

**#include \<sys/user.h\>**

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

*struct* *kinfo\_file* *\**\

**kinfo\_getfile**(*pid\_t pid*, *int \*cntp*);

## DESCRIPTION

This function is used for obtaining the file descriptor information of a particular process.

The *pid* field contains the process identifier. This should be the a process that you have privilege to access. The *cntp* field allows the caller to know how many records are returned.

This function is a wrapper around [sysctl(3)](/sysctl/3.md) with the KERN\_PROC\_FILEDESC mib. While the kernel returns a packed structure, this function expands the data into a fixed record format.

## RETURN VALUES

On success the **kinfo\_getfile**() function returns a pointer to an array of *struct* *kinfo\_file* structures as defined by ⟨sys/user.h⟩. The array was obtained by an internal call to [malloc(3)](/malloc/3.md) and must be freed by the caller with a call to [free(3)](/free/3.md). On failure the **kinfo\_getfile**() function returns NULL.

## SEE ALSO

[free(3)](/free/3.md), [kinfo\_getvmmap(3)](/kinfo_getvmmap/3.md), [malloc(3)](/malloc/3.md), [sysctl(3)](/sysctl/3.md)

## HISTORY

The **kinfo\_getfile**() function first appeared in FreeBSD 7.0.
