- Frequently, you will want to create a child process and set up one end of a pipe as its standard input or standard output.
- Using the dup2 call, you can equate one file descriptor with another.
dup2(fd,STDIN_FILENO);
- The symbolic constant STDIN_FILENO represents the file descriptor for the standard input, which has the value 0.
- The following http://siber.cankaya.edu.tr/SystemsProgramming/cfiles/dup2.cprogram, (see Fig. 1.4.2) uses dup2 to send the output from a pipe to the sort command.
Figure 11:
Redirect Output from a Pipe with dup2
|
2006-03-31