Hello everyone I am trying to do the following: Create two children who imitate this command
cat <infile | wc -c> outfile
using
./a.out infile "cat" "wc -c" outfile
For that, I do a pipe at the beginning so that in the first child I dup2 (fd [1], 1); then I run
| execve (argv [2], ARGS, envp) |
in ARGS we have {"/ bin / cat", "infile", "NULL"};
So in the second child, I have the output of the previous program in fd [0], however I have no idea how to use it in order to pass it back as input to the wc-c.
infile
for reading.outfile
for writing.dup2
) infile
's descriptor onto fd 0.dup2
) the writer end of the pipe onto fd 1.infile
's descriptor.outfile
's descriptor.cat
.dup2
) the reader end of the pipe onto fd 0.dup2
) outfile
's descriptor onto fd 1.infile
's descriptor.outfile
's descriptor.wc -c
.infile
's descriptor.outfile
's descriptor.Error checking is left to you.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.