Question
Using the C code given below modify it so that, 1) the parent process results from the child 2) and add filtering/aggregation. C code: #include
Using the C code given below modify it so that,
1) the parent process results from the child
2) and add filtering/aggregation.
C code:
#include
#include
#include
#include
#include
int main(int argc, char * argv[]) {
int pipe1[2];
pid_t childPID;
char buffer;
if (argc != 2) {
fprintf(stderr, "Usage: %s ", argv[0]);
exit(EXIT_FAILURE);
}
if (pipe(pipe1) == -1) {
fprintf(stderr, "%s", "pipe has failed. ");
exit(EXIT_FAILURE);
}
childPID = fork();
if (childPID == -1) {
fprintf(stderr, "%s", "fork has failed. ");
exit(EXIT_FAILURE);
}
if (childPID == 0) {
printf("I am the child. ");
close(pipe1[1]);
printf("Child is about to read from the pipe. ");
while (read(pipe1[0], &buffer, 1) > 0)
write(STDOUT_FILENO, &buffer, 1);
write(STDOUT_FILENO, " ", 1);
close(pipe1[0]);
printf("Child has echoed from the pipe to standard output. ");
exit(EXIT_SUCCESS);
}
else {
printf("I am the parent. ");
close(pipe1[0]);
write(pipe1[1], argv[1], strlen(argv[1]));
close(pipe1[1]);
printf("Parent has written data into the pipe. ");
printf("Parent will wait for child to terminate. ");
wait(NULL);
exit(EXIT_SUCCESS);
}
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started