mirror of https://github.com/mkerrisk/man-pages
dup.2: Rewrite the description of dup() somewhat
As can be seen by any number of StackOverflow questions, people persistently misunderstand what dup() does, and the existing manual page text, which talks of "copying" a file descriptor doesn't help. Rewrite the text a little to try to prevent some of these misunderstandings, in particular noting at the start that dup() allocates a new file descriptor. Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
This commit is contained in:
parent
18e408ec5f
commit
f5270fe6f8
18
man2/dup.2
18
man2/dup.2
|
@ -53,18 +53,22 @@ dup, dup2, dup3 \- duplicate a file descriptor
|
|||
.SH DESCRIPTION
|
||||
The
|
||||
.BR dup ()
|
||||
system call creates a copy of the file descriptor
|
||||
.IR oldfd ,
|
||||
using the lowest-numbered unused file descriptor for the new descriptor.
|
||||
system call allocates a new file descriptor that refers to the same
|
||||
open file description as the descriptor
|
||||
.IR oldfd .
|
||||
(For an explanation of open file descriptions, see
|
||||
.BR open (2).)
|
||||
The new file descriptor number is guaranteed to be the lowest-numbered
|
||||
file descriptor that was unused in the calling process.
|
||||
.PP
|
||||
After a successful return,
|
||||
the old and new file descriptors may be used interchangeably.
|
||||
They refer to the same open file description (see
|
||||
.BR open (2))
|
||||
and thus share file offset and file status flags;
|
||||
Since the two file descriptors refer to the same open file description,
|
||||
they share file offset and file status flags;
|
||||
for example, if the file offset is modified by using
|
||||
.BR lseek (2)
|
||||
on one of the file descriptors, the offset is also changed for the other.
|
||||
on one of the file descriptors,
|
||||
the offset is also changed for the other file descriptor.
|
||||
.PP
|
||||
The two file descriptors do not share file descriptor flags
|
||||
(the close-on-exec flag).
|
||||
|
|
Loading…
Reference in New Issue