---
name: "closefrom"
section: "2"
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/close_range"
---

# closefrom(2)

delete open file descriptors

Part of [close\_range(2)](/close_range/2.md).

## NAME

**closefrom**, **close\_range** – delete open file descriptors

## LIBRARY

Standard C Library (libc, -lc)

## SYNOPSIS

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

*void*\

**closefrom**(*int lowfd*);

*int*\

**close\_range**(*u\_int lowfd*, *u\_int highfd*, *int flags*);

## DESCRIPTION

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.

## SEE ALSO

[close(2)](/close/2.md)

## 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.
