Question: Using the C code given below modify/fix it so that, 1) the parent process results from the child 2) and add filtering/aggregation. The C code

Using the C code given below modify/fix it so that,

1) the parent process results from the child

2) and add filtering/aggregation.

The C code is given below:

#include

#include

#include

#include

#include

#include

#include

#include

#include

#define INPUT_END 1

#define OUTPUT_END 0

int main(int argc, char* argv[]) {

pid_t pid1;

pid_t pid2;

int p[2]; //declare pipe

pipe(p); //opening pipe

pid1 = fork(); //forking

if(pid1==0) {

close(p[INPUT_END]); //close input

dup2(p[OUTPUT_END], STDIN_FILENO); //redirect

close(p[OUTPUT_END]); //close output

execlp("wc", "wc", "-l",(char*) NULL);

}

else {

pid2 = fork();

if(pid2==0) {

close(p[OUTPUT_END]); //close output

dup2(p[INPUT_END], STDOUT_FILENO); //redirect

close(p[INPUT_END]); //close input

execlp("ls","ls","-l",(char*) NULL);

}

close(p[OUTPUT_END]);

close(p[INPUT_END]);

waitpid(-1, NULL, 0);

waitpid(-1, NULL, 0);

}

}

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 Databases Questions!