closefrom(2)

closefrom2

Delete open file descriptors

Usage

#include <unistd.h>

void

closefrom(int lowfd);

int

close_range(u_int lowfd, u_int highfd, int flags);

Library

Standard C Library (libc, -lc)

Overview

The closefrom() system call deletes all open file descriptors greater than or equal to lowfd from the per-process object reference table. Any errors encountered while closing file descriptors are ignored.

The close_range() system call deletes all open file descriptors between lowfd and highfd inclusive, clamped to the range of open file descriptors. Any errors encountered while closing file descriptors are ignored. Supported flags:

CLOSE_RANGE_CLOEXEC

Set the close-on-exec flag on descriptors in the range instead of closing them.

CLOSE_RANGE_CLOFORK

Set the close-on-fork flag on descriptors in the range instead of closing them.

Return values

Upon successful completion, close_range() returns a value of 0. Otherwise, a value of -1 is returned and the global variable errno is set to indicate the error.

Errors

The close_range() system call will fail if:

[EINVAL]

The highfd argument is lower than the lowfd argument.

[EINVAL]

An invalid flag was set.

Releases

41 releases since FreeBSD 7.3-RELEASE; the text changed 29 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
  28. 13.1–13.2
  29. 13.3–14.5
  30. 15.0–16.0

History

The closefrom() function first appeared in FreeBSD 8.0.

The close_range() function first appeared in FreeBSD 12.2.

The CLOSE_RANGE_CLOFORK flag appeared in FreeBSD 15.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.