CSCI 3150 – Assignment 1
Contents
1 Change Log 3
2 Introduction 3
2.1 Execution of any Linux program . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.2 Shell-specific commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.2.1 gofolder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.2.2 push,pop and dirs . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.2.3 bye . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.3 Basic signal handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.4 Basic command chaining . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
3 The Assignment Package 8
4 Your assignment 8
4.1 To begin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
4.2 Submitting your assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1
5 Assumptions 10
6 Grading 10
7 Questions 11
8 Academic Honesty 12
9 General Notes 12
2
1 Change Log
1.0 This version
2 Introduction
In this assignment, you are going to implement a mini-shell, namely, asg1-shell, using C.
If one invokes the program asg1-shell, we shall see something like this:
Figure 1: Your shell
The prompt has the format of [3150 Shell:<current directory>]=>. Your shell shall
support:
Execution of any Linux built-in command (e.g., ls).
Five shell-specific commands: gofolder, push, pop, dirs and bye.
Basic signal handling: i.e., a user cannot exit the shell simply by typing ctrl-c.
Basic command chaining: && and k.
Basic error handling.
2.1 Execution of any Linux program
Your shell shall allow a user to execute any Linux program, with basic error handling. Note
that the user can input either an absolute path (e.g., /bin/ls) or just a filename (e.g.,
ls). If an absolute path is not given, your shell should search the program in the following
sequence:
3
/bin → /usr/bin → . (current directory)
In case your shell cannot locate the program, your shell should report an error message
“{command name}: command not found” (see Figure below).
*
2.2 Shell-specific commands
2.2.1 gofolder
This command is similar to cd command in Linux, for changing the working directory, like
below:
4
After a successful operation, your prompt shall be updated with current directory name.
Please note that you are just required to implement basic changing of directory as shown
above.
2.2.2 push,pop and dirs
These commands behave similarly to Linux commands pushd, popd, and dirs.
On push [directory path], the shell shall (1) push the current directory to a stack,
(2) change to the directory specified by [directory path], and (3) print the content
of the stack.
On dirs, the shell shall print the content of the stack. The format is:
[item number] [path]
With the most recent item starts with item number 0 and the oldest item in the stack
has the largest item number.
On pop, the shell shall (1) pop an item from the stack, (2) change to that directory
and (3) print the content of the stack.
If the end of the stack is reached, the shell should prompt the user:
pop: directory stack empty
Example:
5
2.2.3 bye
This command is equivalent to exit command in Linux, which lets a user to terminate the
shell (and back to the normal Linux bash shell).
2.3 Basic signal handling
Your shell shall handle the following list of signals as follow:
Signal Action
SIGINT (Ctrl + C) Ignore the signal.
SIGTERM (default signal of command “kill”) Ignore the signal.
SIGQUIT (Ctrl + \) Ignore the signal.
SIGTSTP (Ctrl + Z) Ignore the signal.
6
2.4 Basic command chaining
Your shell should handle two logical operations: AND(&&) and OR(k), like below:
7
3 The Assignment Package
You should have opened a Github account and told us your github account by filling up a
Google form during your assignment 0. So, after logging in your Github account, come here
https://classroom.github.com/a/KKQgMaHn to get a new repo for this assignment. The
new repo should contain the starter package for this assignment.
4 Your assignment
You are given the following files:
Name Description
/asg1-shell.c Source code of a runnable but non-functioning shell
(Work on it).
/asg1-shell Executable of a runnable but non-functioning shell.
(Try to run it; Type ctrl-d to quit)
/demo-asg1 Executable, serve as the demo of what you shall
implement. Our grading will also use this to define
test cases. That is, the behavior of your shell shall
exactly follow this demo.
/hello Executable, a hello world program.
/testcases/data Test data.
/Makefile Makefile to compile asg1-shell.
/grader.sh We will run this script to grade your assignment
(Don’t touch).
8
4.1 To begin
Make, then run grader.sh, you shall see something like this:
This shell script feeds in some test cases to asg1-shell (barely functioning, but you
should make it functioning in this assignment) and demo-asg1 (which is functioning, but no
source code is given) to match their outputs, and reports the number of test cases passed.
Initially, it shall report that none of the test cases passes. Your job is to make all test cases
pass:
If you invoke the grader script like the following:
./grader.sh 2
Then it only runs test case 2 for you.
9
4.2 Submitting your assignment
Follow the procedure in assignment 0.
5 Assumptions
You can assume the following always holds in this assignment:
Input
An input command line has a maximum length of 255 characters, including the trailing
newline character.
An input command line ends with a new line character \n
There would be no leading or trailing space characters in the input command line.
A token is a series of characters without any space character. Each token is separated
by exactly one space character only.
There will be no combination of shell commands in command chaining. For example,
no test cases like ls || bye, bye && bye, bye || ls are defined.
Your shell should also be terminated by ‘Ctrl-D’, the end-of-file character (NOT signal)
upon receiving in the prompt.
6 Grading
1. The TA will fetch and grade your latest version in your repo as of April 25, 2019,
11:00AM. Remember to commit and push before the deadline.
2. Your shell shall output results to standard output stream (stdout). Otherwise, you
will get 0 mark.
3. The objective of this assignment is to let you practice the necessary system programming
skills. So you are not allowed to do your assignment in a way that violates that
10
objective. Therefore, you cannot invoke system(3) library call, invoke any existing
shell programs, including but not limited to: “/bin/sh”, “/bin/bash”, “pushd”, calling
non built-in linux libraries and etc. Otherwise, you will score 0 mark. If you have
doubts about the legitimacy of your program, you may ask on Piazza.
4. Your shell should not leave any zombies in the system when it is ready to accept a new
user input. Otherwise, you will have 1 test case marks deducted.
5. There are 30 test cases in total. Test case 6 and test case 24 carry more weight – each
carries 6.25 mark. Each of the rest carries 3.125 mark.
6. Maximum assignment score is 100.
7. FAQ: Why the grader says a test case fails even if I test my shell under a terminal
without any problem?
Answer: This error usually appears if you forget to handle some error cases. In the
figure below, you can see a command ‘command not exists’ was fed to your shell.
This is a wrong command, therefore your shell cannot execute that and return to
the command prompt. One common case is that the child that handles the wrong
command still exists as exec*() fails. Therefore it is the child prompting you for
input instead of the parent. As the result, you need to bye twice in order to return to
the Linux shell. In this scenario, the grader will report a failed test case.
7 Questions
If you have doubts about the assignment, you are encouraged to ask questions on Piazza
using the corresponding tag. Please focus on knowledge. Unhealthy questions/comments
11
that focus on scores and grades are not encouraged.
If you find any (possible) bugs, send private questions on Piazza to us instead
— otherwise that may cause unnecessary panic among the class if that is not a real bug.
8 Academic Honesty
We follow the University guide on academic honesty against any plagiarism.
9 General Notes
This specification and our grading platform are both based our given course VM. You
should compile, debug and run the assignment program on that VM. So, if you insist
to develop on another platform other than our VM and got any question, test it on
our VM before you ask.