Question: 1) We require to use 4 pipes 2) We will have a shared constant string, e.g. World 3) Parent gets a string from stdin,

1) We require to use 4 pipes 2) We will have a shared constant string, e.g. " World" 3) Parent gets a string from stdin, e.g. "Hello" 4) Parent forks a child and sends the child this string 5) Child concats the string that it received from the parent with the constant string and returns the result back to the parent, e.g. "Hello World" 6) Parent receives concatenated result from the child, forks another child and forwards the child the result. 7) Second child reverses the string it got from the parent and returns back reversed string, e.g "dlroW olleH" 8) Parent finally prints out reversed string and exits

Use the code below as a template:

#include

#include

#include

#include

#include

#include

int main() {

// We use 4 pipes

// First pipe to send input string from parent

// Second pipe to send concatenated string from child

// Third pipe to send concat string from parent

// Fourth pipe to send reversed string from child

char fixed_str[] = " world";

char input_str[100];

pid_t p; p = fork();

if (p < 0) {

fprintf(stderr, "fork Failed" );

return 1;

}

// Parent process

else if (p > 0) {

p = fork();

if (p < 0) {

fprintf(stderr, "fork Failed" );

return 1;

} else if (p > 0) {

} else {

// child process

exit(0);

}

}

// child process

else {

exit(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!