Homework 4 - Description
Title |
Date Posted |
Date Due |
---|---|---|
|
3 / 22 / 18 |
4 / 17 / 18 |
For your next rite of passage, it's time for you to write your own, simple, shell!
This assignment will give you some experience manipulating processes at a programmatic level, and give you some insight into how your own OS' shell operates.
Specifications
In this assignment, you will create a single C program, bump.c
(a gentler version of bash) that serves
as a simple Linux shell.
You will have several important design decisions to make during the construction of your shell, but specifically, it should perform the following:
The ability to execute all of the binaries at the disposal of bash.
When your shell is prepared to accept a command, it should (like other shells) print the following on the start of the line:
BUMP::<cwd>::
where<cwd>
is the current working directory of your shell.When you start your shell, its cwd should be rooted in the current user's home directory.
Users should be able to change working directories via
cd
Users should be able to execute a secret command that invokes the
supworld
system call that you created in the previous assignment.* Users should have the ability to run another process concurrently with your shell if ended with an
&
* Note: this is not as trivial as it sounds; see section on Zombie Processes below.
* Double note: for example, a user should be able to say BUMP::/home/forns:: ping www.google.com &
and have ping running concurrently with Bump (thus, you could input other Bump commands while ping is running
in the background in the same way that &
works for Bash).
Example Usage
The following provides an example interaction with your bump
shell, but for all other queries, on how it should function,
just open bash!
BUMP::/home/forns:: pwd /home/forns BUMP::/home/forns:: cd .. BUMP::/home:: pwd /home BUMP::/home::
The Zed Word
Just as in reality, parents are responsible for cleaning up after their children.
When a parent spawns a child, it is expected that, after the child has concluded its operation, the parent will request to free its PID from the
OS' job queue, which is typically accomplished using the wait
system call.
However, wait
ing for a child process blocks the parent from execution, which is not always what we want to do (as in the
case of being able to allow commands to run concurrently with a shell via the &
symbol).
The problem: in the absence of a wait
system call, the child process is not reaped once it has completed
until the parent process also terminates.
A zombie process is one that has terminated but has no parent to perform the necessary cleanup after its termination.
Some notes about zombies:
Zombies will not be reaped if the parent has no handling call to
wait
, and will instead waste assigned PIDs, possibly preventing the creation of new processes if we are overrun by a horde of zombies.If the parent that has a zombie infestation terminates, the OS typically has some means of killing them (e.g., Ubuntu adopts the zombies under the
init
process and then kills them appropriately). However, long running processes (like shells) may accrue many zombies if not properly handled.
First things first, let's see a zombie in action; run the following snippet and then use another terminal's ps -el
to
find the parent and child processes. You'll notice that the zombie process has defunct
written next to it, and the status
code of Z
:
int main () { if (fork()) { while (1); } return 0; }
As such, your shell must allow for concurrency without creating any zombie processes!
There is a relatively simple trick to accomplish this, but it is left to you to figure out how (Google will be your friend as well).
Simplifications & Restrictions
Just a couple of notes for this assignment:
To collect user input, use
fgets
, not anyscan
variant (which is defunct and a security risk).No need to support any bash special characters
Submission
What
Submit your zipped bump.c
program on Brightspace!
How
We will (unfortunately) be using Brightspace to submit this assignment, though you should always be using version control to organize your assignments (even text)!
To submit your assignment:
Find this assignment listing on Brightspace.
Upload the .zip file containing your submission.
Make sure to click "submit" after the upload is complete!