Question: write a program that includes a parent process and a child process. The parent process will read a word from standard input and send it
write a program that includes a parent process and a child process. The parent process will read a word from standard input and send it to the child process. The child process will print the first line of a poem that contains the word. If the word is not in any line of the poem, the child process will print a message. The poem is read from a file whose name is provided as a program parameter (argv[1]).
The program starts by reading the poem from a file. The name of the file is given as a parameter. If the filename is wrong or the file cannot be opened, the program prints an error message and exits. The program then creates a pipe (named or unnamed) that the parent and child processes use to communicate. If the pipe cannot be created properly, the program prints an error message and exits. The program will create a child process. After that, the parent and the child processes run concurrently. o The parent process keeps reading a word from the standard input and writes the word to the pipe. The parent process exits when the word is quit. o The child process will read a word from the pipe and search for the word in the poem. If the word is not in the poem, it prints a message that the word is not found. Otherwise, it prints the first line where the word appears in the poem.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
