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) */

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




}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!