Question: 1. write a C program i) using system calls fork, wait, execvp, open, close, dup, dup2, and pipe ii) use Command Line Interpreter (CLI) 2.

1. write a C program
i) using system calls fork, wait, execvp, open, close, dup, dup2, and pipe
ii) use Command Line Interpreter (CLI)

2. More details
A “shell” is also known as command line interpreter.
First, your shell must have a prompt string. You can choose any prompt you like. It may look like the
following:
PURDUE> ls –l
In the above example, “PURDUE>” is the prompt string, “ls” is a command name, and “-l” is an argument of
the command. The command name is usually the filename of the executable.

3. Shell Language Grammar
The following shows the grammar for your users to compose a valid shell command. Program should be able to parse an input line, and decide if the user’s input is valid or not.
In the grammar below, [obj] denotes obj inside [ ] is optional; “|” denotes Unix pipe; “*” denotes 0
or >=1 occurrences..

About “&”: The input command line will be running as a background process. Note that a shell must wait until the program completes unless the user runs a background process (i.e., using &).

5. Programing requirement:
your program and shell should support following features:-
1) Program should keep accepting new commands lines until users input “exit”. Your shell should
have a prompt string.
2) A user’s command line may or may not have “<” at the beginning.
3) A user’s command line may or may not have “>” in the end.
4) There may be up to 9 pipes in a command line (it’s OK if you want to support more than 9 pipes).
5) A user may run a command line as a background process (i.e., the command line ends with “&”).


Here are two example command lines that are valid:
PURDUE> cat < aaa | more | more | grep 2 | sort | head | wc > bbb &
PURDUE> cat < aaa | more | more | grep 2 | sort | head | wc > bbb


Here are two example command lines that are not valid:
PURDUE> ls | cat < tmp.txt
PURDUE> ls > tmp.txt | more

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

a C program that implements a simple shell with the specified features using system calls fork wait ... View full answer

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 Operating System Questions!