Question: 2. Using the system calls we discussed in class, your goal is to create a program that executes the following command which will count the
2. Using the system calls we discussed in class, your goal is to create a program that executes the following command which will count the number of occurrences of "color" in the file and write the results to newfile.txt, grep -o color colorfile.txt -> newfile.txt More details: a. Create two argument vectors: One for grep -o color colorfile.txt ii. One for wew An example argument vector would be: char *wyargvl 1=(char*) "Is", (char*"-1". NULL): b. create a pipe c fork the process d. child will call dup2 to hook standard output to one end of the pipe. Then, execute the grep command using execvp e parent will call dup2 to hook standard input to the other end of the pipe. 1. parent will also call dup2 to hook standard output to the file called newfile.txt Then, execute the wc command using execup Sample run for question 2: %pipes *cat newfile.txt 5
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
