Question: pipes_process1.c : pipes_processes2.c : scores: Please code in C 2. Chaining Processes together using two Pipes Example Program of chaining processes together using two Pipes

 pipes_process1.c : pipes_processes2.c : scores: Please code in C 2. ChainingProcesses together using two Pipes Example Program of chaining processes together using

pipes_process1.c :

two Pipes This following C program in (pipes_processes2.c) creates two processes P1(Parent - executes cat ) and P2 (Child - execute grep ).One the command line a user would be executing the command cat

scores grep Lakers . The output of cat scores would be the

pipes_processes2.c :

input to grep Lakers , chaining the two programs together. In thisquick-and-dirty software implementation of the command line example the parent doesn't wait

scores:

for the child to finish and so the command prompt may reappear

Please code in C

2. Chaining Processes together using two Pipes Example Program of chaining processes together using two Pipes This following C program in (pipes_processes2.c) creates two processes P1 (Parent - executes cat ) and P2 (Child - execute grep ). One the command line a user would be executing the command cat scores grep Lakers . The output of cat scores would be the input to grep Lakers , chaining the two programs together. In this quick-and-dirty software implementation of the command line example the parent doesn't wait for the child to finish and so the command prompt may reappear before the child terminates. Example: cat scores grep 28 Output Indiana 45 28.616 Houston 44 28.611 Oklahoma City 44 28.611 Utah 44 28.611 Task Modify the code in a new file (pipes_processes3.c) to take one argument from the command line using argc and argv that is the argument passed to the grep program (e.g. Lakers or 28), then create three processes P1 (Parent - executes cat scores ) and P2 (Child - execute grep ) and P2 (Child's Child - execute sort ). The output of cat scores would be the input to grep Lakers , and int output from grep Lakers would be the input for sort Example: cat scores grep 28 sort Input $./pipes_processes3 28 Output Houston 44 28.611 Indiana 45 28.616 Oklahoma City 44 28.611 Utah 44 28.611 #include #include #include #include #include #include int main() { // We use two pipes // First pipe to send input string from parent // Second pipe to send concatenated string from child int fd1[2]; // Used to store two ends of first pipe int fd2[2]; // Used to store two ends of second pipe char fixed_str[] = "howard.edu"; char fixed_str2[] = "gobison.org"; char input_str[100]; char input_str2[100); pid_t p; if (pipe (fd1)==-1) { fprintf(stderr, "Pipe Failed" ); return 1; } if (pipe(fd2)==-1) { fprintf(stderr, "Pipe Failed" ); return 1; printf("Enter a string to concatenate:"); scanf("%s", input_str); fork(); = if (p 0) { close(fd1[0]); // Close reading end of pipes close(fd2[0]); // Write input string and close writing end of first // pipe. write(fd1[1], input_str, strlen(input_str) +1); // Wait for child to send a string wait(NULL); //concatenate 2nd fixed string char concat_str2[100]; read(fd2[0], concat_str2, 100); int k2 = strlen(concat_str2); int 12; for(i2=0; 12

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!