COMS W4118 Spring 2008: Homework Assignment 1
Updated Feb 7 2008
Due Tuesday, February 12th at 9:10 AM (beginning of class)
This homework consists of two components: written assignment and
programming assignment. Each is to be submitted via Courseworks.
Both components of the assignment are to be done alone, not in
teams. Discussion is encouraged but collaboration is not allowed.
Written Assignment
Exercise numbers refer to the course textbook, Operating System
Concepts with Java. Each problem is worth 5 points.
- Exercise 1.3
- Exercise 1.10
- Exercise 1.11
- Exercise 1.17
- Exercise 2.3
- Exercise 2.4
- Exercise 2.8
- Exercise 2.14
You should submit your assignment via Courseworks->Class Files->Shared Files.
Upload your answers in a single ASCII text file. The filename
should be
HW1.<uni>.txt For example, if your uni is sa3152, your
submission filename should be HW1.sa3152.txt
Programming Assignment: Shell implementation
Description
A shell is a piece of software which provides an interface for
users. It interprets user commands and executes them. Some shells
provide simple scripting terms such as if or while, and allow users to
make a program which facilitates their computing life. There are two
categories of shells: command line and graphical. Intuitively, command
line shells provide command line user interface commonly used in
Unix/Linux environments, while graphical shells provide graphic user
interface(GUI) such as MS Windows. In this assignment, we will focus on
command line shells.
One of the interesting features of shells provided in Unix/Linux is
a pipeline:
$ cmd1 | cmd2 | cmd3
This command connects the standard output of cmd1 to the standard
input of cmd2, and again connects the standard output of cmd 2 to the
standard input of cmd3. Common usages of this feature are ls -al | more
or who | wc -l.
In this assignment, you will implement your own shell.
Purpose
- Introduce basic Linux programming environment
- Familiarize students with Linux programming using several system
calls
Programming Assignment
1. (10 points) Write a simple shell. Basically your shell should
read the line
from standard input, parse the line with command and arguments, and
execute the command with arguments. You should use fork and exec system
calls.
- The shell should find the command in your current working
directory first. If not found, it should search the directories in the
shell's pathname list which will be explained in the part 2.
- You are not allowed to use system function in the standard
library.
- You may assume that arguments are separated by white spaces. You
do not have to deal with special characters such as ', ", \, <,
>, etc. One exception is the pipeline character (|).
2. (20 points) Implement the following built-in commands.
- exit: users can exit from the shell with the exit command.
- cd: cd is a command to change directories. You will need to
invoke the chdir system call.
- path: path is a command not only to show the current pathname
list, but also to append or remove several pathnames. You may keep an
variable or data structure to deal with pathname list. This list helps
searching for executables when users enter specific commands.
- path (without arguments) displays the pathnames currently set.
It should show pathnames seperated by colons. ex) "/bin:/usr/bin"
- path + /foo/bar appends the pathname to the "path" variable.
- path - /foo/bar removes the pathname from the "path" variable.
3. (20 points) Extend your shell with pipeline (|).
- You should use following system calls: fork, exec*, pipe, dup2,
wait, close.
- The depth of pipeline is limited to 2. It means that you should
deal with commands like
cmd1 | cmd2
or cmd1 | cmd2
| cmd3
. No bonus points for deeper pipeline implementation.
Special Note - Clarifications
- For all the above programs you should not make use of execlp or execvp.
You are free to use any sys call from the exec* family which does not
make use of the native shell PATH environment variable.
- We do not want to put a restriction on the system calls you may use.
You are free to use any other system calls and any data-structures but
you must justify it's use in your README file.
- There are no restrictions on the length of a command line and number of
arguments to a given command.
Requirements
You should submit your assignment via Courseworks->Class Files->Shared Files. Post a single archive
file including all of your files. The filename should be
HW1.<uni>.tar.gz. For example, if your uni is sa3152, your
submission filename will be HW1.sa3152.tar.gz.
- Use the C language. Other languages are not allowed. No
exceptions.
- Include all source code, a Makefile, and a descriptive README
file.
- The executable filename of your shell should be "myshell". Please do no
include the binary as part of you archive
Make sure that your program compiles and runs correctly on the CS CLIC machines. To grade
this assignment, we will extract your submission file, type make, and
run myshell.
References
- Linux man pages
- C Language
- Unix/Linux System programming
- Standard C Library