up | Inhaltsverzeichniss | Kommentar

Manual page for DUP(2V)

dup, dup2 - duplicate a descriptor

SYNOPSIS

int dup(fd)
int fd;

int dup2(fd1, fd2) int fd1, fd2;

DESCRIPTION

dup() duplicates an existing object descriptor. The argument fd is a small non-negative integer index in the per-process descriptor table. The value must be less than the size of the table, which is returned by getdtablesize.2 The new descriptor returned by the call is the lowest numbered descriptor that is not currently in use by the process.

With dup2(), fd2 specifies the desired value of the new descriptor. If descriptor fd2 is already in use, it is first deallocated as if it were closed by close.2v

The new descriptor has the following in common with the original:

Thus if fd2 and fd1 are duplicate references to an open file, read.2v write.2v and lseek.2v calls all move a single seek pointer into the file, and append mode, non-blocking I/O and asynchronous I/O options are shared between the references. If a separate seek pointer into the file is desired, a different object reference to the file must be obtained by issuing an additional open.2v call. The close-on-exec flag on the new file descriptor is unset.

The new file descriptor is set to remain open across exec system calls (see fcntl.2v

RETURN VALUES

dup() and dup2() return a new descriptor on success. On failure, they return -1 and set errno to indicate the error.

ERRORS

EBADF
fd1 or fd2 is not a valid active descriptor.
EMFILE
Too many descriptors are active.

SEE ALSO

accept.2 close.2v fcntl.2v getdtablesize.2 lseek.2v open.2v pipe.2v read.2v socket.2 socketpair.2 write.2v


index | Inhaltsverzeichniss | Kommentar

Created by unroff & hp-tools. © somebody (See intro for details). All Rights Reserved. Last modified 11/5/97