CS474: Operating Systems I
Spring 2008
Programming assignment # 1 - Simple Shell
Assigned : 2/12/08
Due: midnight 2/24/07 (Sun)
Submission: Send your source code
and a short report using the
submission webpage
Total points: 40
Important
material - Unix
man page on Linux. Read the following man pages:
fork,
wait, strtok, dup2, execv (execl), getenv, setenv
example code from S. Cooper:
parser.c
simple
child.c
STDIN/OUT
example
Tasks:
A shell can be thought of as an infinite loop which takes
commands and execute them, and then gives another prompt such as "%".
while (1)
{
read in a line
parse the input line
execute the line (if possible)
print out prompt
}
Your job is to write a shell which takes in commands from
standard input, executes
the commands.
Your shell will allow the following features:
(a). Allow a user to use the "nslookup"
command with a direct path (/usr/bin/nslookup) to look up the IP
address if the name of the
machine is given.
(b). Allow a user to execute a program in background. For example, it
allows a user to use "emacs&".
(c). Allow a user to check and set path
environment variable.
(d). If a user types a command without its direct path, your shell will
search through the paths in the environment variable path. If the correct path of the
command is found in the path
variable, execute the command. Otherwise, print "command not found" on
the screen.
(e). Allow a user to use "ls" and redirect the output to a file.
"PATH" is an ordered list of absolute paths separated by a blank. For
example, if I type:
%echo $path
I will get the following:
/home/shen3/jinghe/EMAN/bin
/home/shen3/jinghe/Chimera/bin /local/ssh/bin /local/sicstus3.7/bin
......
This means that any executable programs will be searched through the
above path in the order specified in the"path".
I can set the "path" environment variable by typing:
%set
path=(/home/shen3/jinghe/Helixtracer $path)
The above command will add a path, /home/shen3/jinghe/Helixtracer, to
the
existing search paths.
Testing:
An example of the test looks like the following. Suppose "myShell" is
your executable code. I will run "myShell" and
then test commands such as the following:
/usr/bin/nslookup cobra
/usr/bin/xemacs&
echo $path
set path=(
/usr/bin $path)
echo $path
ls >filename
xemacs
Report:
Write a short report describing the design and the features provided.
If your program provides extra features, describe how to use them.