Question: Write a simple shell in C++/C completes 2 tasks: Part 1: The shell handles one command + The shell starts with displaying a prompt and

Write a simple shell in C++/C completes 2 tasks:

Part 1: The shell handles one command + The shell starts with displaying a prompt and then waits for input as a command. Example: shell$echo hello world You shell should exit after the command is executed. + Your shell should read a line from stdin. This line should be parsed out into command name and all its arguments. You may assume that the only supported delimiter is the whitespace character. The above command should be tokenized into three words: echo, hello, world! + After parsing and lexing the command, your shell should execute it by using fork() to create a child process that in turn invokes execvp() on the command. + The parent should wait for the child process to terminate before exiting. The parent should wait on termination of its child and then print the childs PID and exit status. If the child fails to execute the desired command using execvp(), it should print an error message using perror() and exit with a code of 1. Otherwise, it should exit with a code of 0. Part 2: Run a Pipeline of Commands using Pipes + Augment your shell (implemented part A) to be capable of executing a sequence of programs that communicate through a pipe. For example, if the user types ls | wc -l, your shell should fork two child processes that each executes one command (by execvp()), which together will calculate the number of files and directories in the current directory. While this example shows two processes communicating through a pipe, your shell should support pipes between more than two processes. + Your code should check return values of all system calls including fork, execvp, wait, dup2, pipe, exit, etc.

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!