Synopsis

#include <unistd.h>

int dup(int fildes);
int dup2(int fildes, int fildes2);

Description

dup() duplicates an existing object descriptor and returns its value to the calling process. The argument fildes is a small non-negative integer index in the per-process descriptor table. The new descriptor returned by the call is the lowest numbered descriptor currently not in use by the process.

In dup2(), the value of the new descriptor fildes2 is specified. If fildes and fildes2 are equal, then dup2()just returns fildes2; no other changes are made to the existing descriptor. Otherwise, if descriptor fildes2 is already in use, it is first deallocated as if a close(2) call had been done first.

Return value

Errors