In this project you will write a simple Unix shell in C. The project can be done in groups of up to 2 students and is due April 30. The shell should have the following functionality:
$ ls | | more ^Syntax error in pipeline.For errors in system calls, use perror() (see man 3 perror).
A shell can do far many more things, but you are only required to do the ones above. Your basic program should follow fig. 1-19 in the textbook; then, expand it appropriately to handle pipelines, run a process in the background, parse the command line, etc. You will need to understand well the following system calls (or similar ones): fork, execve, dup, pipe, open, close, exit, wait. To see their description and parameters, read their manual page (section 2 for system calls: man 2 fork; section 3 for library functions, e.g. man 3 perror).
The crucial bit is to get a pipeline A | ... | Z to work. First focus on understanding the simple case A | B. To get a pipeline A | B to work, you'll need to:
For a more complex pipeline, apply this technique over a loop. Redirection works similarly but opening a file instead of a pipe. Other issues (e.g. how to store the command line, parse it, etc.) are left up to you; keep things simple.
Examples to try with your shell:
Your mysh should produce (almost) the same result as running them from the system shell (sh, bash, etc.).
You can use strace and ltrace to trace the calls to system calls and library functions.
What you have to submit is a single file project1.tar.gz, by email to the TA, containing: