Unix Shell
- Submission format: as "tar" archive of your program source and
documentation e-mailed directly to our TA. Documentation should be in
the form of a plain text (README.txt) or html page (README.html) that
includes:
- clear & concise instructions on how to compile your program
- clear & concise instructions on how to use or test your program
- clear & concise description of your program including the
names of files and the functionality they implement.
- This tar archive should be prepared in the following manner
- your assignment should be in a directory [username]-lab1 where
you substitute your cs username for [username]
(e.g. freudent-lab1).
- From the directory above the lab
directory, run the command:
$ tar cf [username]-lab1.tar username-lab1
- You can find more info on tar in the unix manual
($ man tar).
- Your grade will be based on:
- how much of the assignment you have implemented
- how correctly your assignment works
- the "readability" of your program source code
- The clarity of your documentation. You will lose points if it
is difficult for the TA to figure out how your program works or how
to compile it.
Assignment
In this lab, you will create a user shell in the C programming
language that can understand:
- simple commands (e.g. $ /bin/ls )
- simple pipes (e.g. $ /bin/ls | /bin/sort -r)
- background tasks (e.g. $ find /etc -print & )
- built-in commands: "var=value" and "cd" -- for "cd" you will need
to lookup the library routine "chdir" in the (online) unix manual
Programs that cannot be exec'd or terminate with errors (non-zero
exit codes) should be reported.
Your lab must directly use the posix calls:
- pipe()
- fork()
- dup() or dup2()
- execve()
- wait() or waitpid()
- close()
These system calls are documented in chapter 2 of the unix manual
(e.g. $ man 2 fork).
In addition, your program should dynamically allocate memory using the
library calls malloc and free. You may (if you like)
use calloc and strdup which are part of the same library.
Please clearly indicate in your submission on which system your lab
was tested (including architecture & os).
Useful Snippets
I wrote a few short programs to help you figure out how to use a few
of the system calls. They're all in lab1Demos,
and packed together in a single gzipped tarfile.
- argDemo: print command line arguments (how argv works)
- envDemo: print the contents of envp (how envp works)
- forkPipeDemo: a short program that uses fork & pipe
- exec.c: a short program using exec
Grading
Our TA will assess:
- documentation/readability/software engineering
- exec properly
- fork properly (shell does not terminate with commands...).
Includes checking if program failed (exit code != 0).
- pipe between commands
- background commands
- proper use of PATH environment variable
- proper functioning of environment variables
- proper functioning of change-directory builtin (cd)