dup2(2) — 4 BSD
NAME
dup2 − duplicate a descriptor
SYNOPSIS
int dup2 (oldd, newd)
int oldd, newd;
DESCRIPTION
dup2 duplicates file descriptor oldd. The desired value of the new descriptor, newd, is specified. If this descriptor is already in use, the descriptor is first deallocated as if a close(2) call had been done first.
RETURN VALUE
The value −1 is returned if an error occurs in either call. The external variable errno indicates the cause of the error.
ERRORS
dup2 fails if:
[EBADF] Oldd or newd is not a valid active descriptor.
[EMFILE] Too many descriptors are active.
SEE ALSO
dup(2), accept(2), open(2), close(2), pipe(2), socket(2), socketpair(2), getdtablesize(2).
CX/UX Programmer’s Reference Manual