Question: A simple shell to handle one command or two Commands in Pipe Your shell will loop to do the following work: (1) read input from
A simple shell to handle one command or two Commands in Pipe
Your shell will loop to do the following work: (1) read input from the standard input (keyboard), (2) parse input, (3) print the parsed result to the standard output (console), (4) run the commands in pipe, and (4) back to the loop.
Each input is one command (e.g., ls) or two commands in pipe (e.g., ls | wc -l or ls | grep ".c").
For example, if there are two commands in pipe, the parent gets the command (for example, "ls | wc -l") to recognize that there are two commands piped together. Thus it will have a pipe to be shared, and then fork a child process (to do "ls") which will fork its child process (to do "wc -l") with the pipe shared (so that the output of one process doing "ls" will be input to the input of the other process doing "wc -l"). Meanwhile the parent process waits till all the child processes are terminated, and then back to the loop for the next command from the user.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
