Function DUP2

Syntax

dup2 file-descriptor copy => error

Arguments and values

file-descriptor -- A non-negative fixnum.

copy -- A non-negative fixnum.

error -- A fixnum.

Description

This function makes copy be a copy of file-descriptor, closing copy first if necessary. However:

After a successful return from this system call, the old and new file descriptors may be used interchangeably. They refer to the same open file description (see open) and thus share file offset and file status flags; for example, if the file offset is modified by using lseek on one of the descriptors, the offset is also changed for the other.

The two descriptors do not share file descriptor flags (the close-on-exec flag). The close-on-exec flag (FD_CLOEXEC; see fcntl) for the duplicate descriptor is off.

Errors

+ebadf+ file-descriptor is not an open file descriptor, or copy is out of the allowed range for file descriptors.
+ebusy+ (Linux only) This may be returned during a race condition with open and dup.
+eintr+ The call was interrupted by a signal.
+emfile+ The process already has the maximum number of file descriptors open and tried to open a new one.