write the 2-level pipe BELOW here #include #include #include int main() { int pfds[2]; pipe(pfds); pid_t pid
Question:
write the 2-level pipe BELOW here
#include
#include
#include
int main() {
int pfds[2];
pipe(pfds);
pid_t pid = fork(); /* 0 (child), non-zero (parent) */
if ( pid == 0 ) { /* The child process*/
close(1); /* close stdout */
dup2(pfds[1],1); /* make stdout as pipe input */
close(pfds[0]); /* don't need this */
execlp("ls", "ls", NULL);
} else { /* The parent process*/
close(0); /* close stdin */
dup2(pfds[0],0); /* make stdin as pipe output */
close(pfds[1]); /* don't need this */
wait(0); /* wait for the child process */
execlp("wc", "wc", "-l", NULL);
}
return 0;
}
Can you rewrite the 2-level pipe example to a for-loop like this?
for (i=0; i<2; i++) {
// Rewrite the 2-level pipe here
}
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill