Add Book to My BookshelfPurchase This Book Online

Chapter 3 - Low-Level I/O Routines

UNIX Systems Programming for SVR4
David A. Curry
 Copyright © 1996 O'Reilly & Associates, Inc.

Duplicating File Descriptors
Sometimes you may want to have more than one file descriptor referring to the same file or a specific file descriptor refer to a file. This is most commonly needed when reassigning the standard input, standard output, and standard error output. The following two functions duplicate file descriptors:
#include <unistd.h>
int dup(int fd);
int dup2(int fd, int fd2);
dup returns a new file descriptor that references the same file as fd. The new descriptor has the same access mode (read, write, or read/write) and the same read/write offset as the original. The file descriptor returned is the lowest numbered one available. dup2 causes the file descriptor fd2 to refer to the same file as fd. If fd2 refers to an already-open file, that file is closed first.
These functions require advanced concepts to demonstrate, so I will defer their demonstration until Chapter 11, Processes.

Previous SectionNext Section
Books24x7.com, Inc © 2000 –  Feedback