kinfo_getfile(3)

kinfo_getfile3

Function for getting per-process file descriptor information

Usage

#include <sys/types.h>

#include <sys/user.h>

#include <libutil.h>

struct kinfo_file *

kinfo_getfile(pid_t pid, int *cntp);

Library

System Utilities Library (libutil, -lutil)

Overview

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) 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) and must be freed by the caller with a call to free(3). On failure the kinfo_getfile() function returns NULL.

Releases

41 releases since FreeBSD 7.3-RELEASE; the text changed 27 times.

  1. 7.3
  2. 7.4
  3. 8.0
  4. 8.1
  5. 8.2
  6. 8.3
  7. 8.4
  8. 9.0
  9. 9.1
  10. 9.2
  11. 9.3
  12. 10.0
  13. 10.1
  14. 10.2
  15. 10.3
  16. 10.4
  17. 11.0
  18. 11.1
  19. 11.2
  20. 11.3
  21. 11.4
  22. 12.0
  23. 12.1
  24. 12.2
  25. 12.3
  26. 12.4
  27. 13.0–13.2
  28. 13.3–16.0

History

The kinfo_getfile() function first appeared in FreeBSD 7.0.

From base 16.0-CURRENT-20261027-61c70dc16a79 in FreeBSD 16.0-CURRENT (2026-10-27). Parsed by carta from the page's mdoc source.