Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts Of Database Management

Authors: Joy L. Starks, Philip J. Pratt, Mary Z. Last

9th Edition

1337093424, 978-1337093422

More Books

Students also viewed these Databases questions

Question

Describe Table Structures in RDMSs.

Answered: 1 week ago