fd(4)

fd4

File descriptor files

Overview

The files /dev/fd/0 through /dev/fd/# refer to file descriptors which can be accessed through the file system. If the file descriptor is open and the mode the file is being opened with is a subset of the mode of the existing descriptor, the call:

fd = open("/dev/fd/0", mode);

and the call:

fd = fcntl(0, F_DUPFD, 0);

are equivalent.

Opening the files /dev/stdin, /dev/stdout, and /dev/stderr is equivalent to the following calls:

fd = fcntl(STDIN_FILENO,  F_DUPFD, 0);
fd = fcntl(STDOUT_FILENO, F_DUPFD, 0);
fd = fcntl(STDERR_FILENO, F_DUPFD, 0);

Flags to the open(2) call other than O_RDONLY, O_WRONLY, and O_RDWR are ignored.

These devices may not be opened by processes which are tainted as a result of setuid or setgid behaviours, as documented in issetugid(2). In those cases, an error return will occur with errno set to EPERM.

Files

/dev/fd/#
/dev/stdin
/dev/stdout
/dev/stderr

Releases

61 releases since OpenBSD 2.1; the text changed 7 times.

  1. 2.1–2.5
  2. 2.6–2.7
  3. 2.8
  4. 2.9–3.3
  5. 3.4–3.8
  6. 3.9–4.1
  7. 4.2–7.9
  8. 8.0

From man 8.0-current-20261101 in OpenBSD 8.0-current (2026-11-01). Parsed by carta from the page's mdoc source.