Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a shell in C/C++ **Prefer this to be written in C++** You do NOT need to be concerned with piping the output of commands

Write a shell in C/C++ **Prefer this to be written in C++**

You do NOT need to be concerned with piping the output of commands to other commands or background job control

Your shell should use the fork system call and the execv system call (or one of its variants) to execute commands. The shell needs to use either wait or waitpid system calls to wait for a program to complete execution. You should recognize the command exit to mean that your shell program should terminate by calling the exit() system call.

A very simple shell such as this needs at least the following components:

a command-line parser to figure out what the user is trying to do.

If a valid command has been entered, the shell should use fork to create a new child process, and the child process should exec the command.

Your shell will need to support file redirection. Use the same syntax as defined in the Bash shell: a single '>' implies that one needs to redirect the standard output of the program being started to the referenced file while a single '<' implies the same with standard input. The double '>>' implies that standard output will append to an existing file rather than create a new file (similar behavior is required for the '<<' operator and standard input). You do not need to implement support for the Bash pipeline operator '|'.

Before calling exec to begin execution, the child process may have to close stdin (file desriptor 0) and/or stdout (file descriptor 0), open the corresponding file and use the dup2 system call to make it the appropriate file descriptor. Don't forget to use the close system call to close the old file descriptor.

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

Database 101

Authors: Guy Kawasaki

1st Edition

0938151525, 978-0938151524

Students also viewed these Databases questions

Question

What is an industry?

Answered: 1 week ago