FD
Section: Devices and Network Interfaces (4)
Updated: EUCC
Index
Return to Main Contents
NAME
/dev/fd/* - ``file descriptor'' driver
SYNOPSIS
pseudo-device fd
DESCRIPTION
/dev/fd/0
-
/dev/fd/19
are special files that reference the files associated with a process'
open file descriptors.
That is, opening the file: /dev/fd/N is equivalent to opening whatever
file you opened to get the file descriptor
N,
even though you may not
know the file's true name (or even if it has one).
This can be used to force a program which opens files by name, to connect
itself to open file descriptors (which you have thoughtfully provided) in
weird and wonderful ways. A simple use would be to force a program which
only accepts input from files, to read from its standard input.
For instance:
cat /dev/fd/0
produces the same result as:
cat -
which would be useful if
cat(1)
didn't use the ``-'' convention.
This driver is particularly useful for enabling the ``process substitution''
mechanism in
ksh(1).
If the open file descriptor references a socket, the driver fakes a
dup(2)
system call instead of actually opening a file. In this case it
checks to see that the read/write mode you are attempting to open
the file with, is compatible with the mode of the existing file descriptor.
That is, if descriptor 5 refers to a socket and
is open for writing, you cannot open
/dev/fd/5
for reading.
As a notational convenience, the files
/dev/stdin,
/dev/stdout,
and
/dev/stderr
are provided as hard links to
/dev/fd/0,
/dev/fd/1,
and
/dev/fd/2
respectively.
ERRORS
The named file descriptor will be ``opened'' as described above unless
one of the following is true.
- [ENXIO]
-
The file descriptor attempting to be reopened is larger than the
maximum number of open files that a process may have.
(E.g., attempting to open file descriptor 65 on a 4.3BSD system.)
- [EBADF]
-
The file descriptor attempting to be reopened is not an open file.
Other errors as would be returned by
access(2),
and
open(2).
SEE ALSO
ksh(1),
access(2),
dup(2),
open(2).
AUTHOR
Fred Blonder <Fred@mimsy.umd.EDU>
NFS version by Arnold Robbins <arnold@emory.EDU>
FILES
/dev/fd/*,
/dev/stdin,
/dev/stdout,
/dev/stderr
BUGS
Since, for sockets,
the driver fakes a
dup
system call rather than actually re-opening
the file, the new descriptor is a copy of the
dup'ed
descriptor, and shares
its properties. Specifically: it will have the same read/write mode as the
dup'ed
descriptor. If descriptor 0 is open for reading and writing, opening
/dev/fd/0
for reading will return a writable, as well as readable, file
descriptor.
Also: the descriptors share the same read/write pointer, so seeks, reads and
writes on one will affect the other.
While not a bug in the driver specifically, use of these files can produce odd
interactions with programs which don't expect to have their file
descriptors surreptitiously aliased.
Having only 20 entries in the
/dev/fd
directory is an anachronism; modern Unix systems allow
a process to have many more open file descriptors.
Index
- NAME
-
- SYNOPSIS
-
- DESCRIPTION
-
- ERRORS
-
- SEE ALSO
-
- AUTHOR
-
- FILES
-
- BUGS
-
This document was created by
man2html,
using the manual pages.
Time: 06:30:35 GMT, December 12, 2024