Duplicate File Descriptors

The section File Descriptors, in Chapter 2, introduced the concept of file descriptors. Typically a file descriptor is returned in response to an open() or creat() system call. The dup() system call allows a user to duplicate an existing open file descriptor.

#include <unistd.h>

int dup(int fildes);

There are a number of uses for dup() that are really beyond the scope of this book. However, the shell often uses dup() when connecting the input and output streams of processes via pipes.

Get UNIX Filesystems: Evolution, Design, and Implementation now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.