CSCI 420 - Operating Systems & Concurrency
Spring 2017
Rush - the Rust Shell, part 2
Assignment
In this assignment, we continue implementing an interactive
Unix shell
using the Rust language. Implement your shell according to the following
steps:
- If the line ends with the
&
symbol, it should run in the background. That is, your shell should not wait for it to terminate; the
command line should immediately return. Your shell should print the PID of
the process, so that the user may later manage it as needed.
- The line may contain two or more commands connected with the pipe symbol
(
|
). If this happens, start a process for each command, setting
up pipes to send the output of each left-hand command to the input of the
following right-hand command.
- If the line contains a
<
symbol, the immediately following
string is the input source for the command. If it contains a >
, the command's output goes to the targeted file.
- The
*
pattern-matching symbol should work with arbitrary paths.
Grading
Completing each step is worth 10 points. Full credit will be received for
completing any three of the steps, so the assignment is worth
30 points. If an additional step is completed, it will be
worth 10 points of extra credit. Furthermore, if the first
three steps are completed and they will all work together
properly on a single command line, that is also worth
10 points of extra credit.
No credit will be given for code that fails to
compile. Partial credit may be given for incomplete or flawed versions of a
given step.
Tips
- The most straightforward implementation of pipes is to use the Rust
std::process
library. This is a very high-level API, and so it will be necessary to run
each process to completion (saving its output) before starting the next
process in the pipe (sending the old output as its input).
- A lower-level approach can use nix, which is a Rust binding to the basic Unix system calls. Each system call
has a corresponding (safe) Rust wrapper. In this case, one can create a pipeline using file descriptors. This creates true parallelism between the processes, but it arguably takes a bit more effort. A successful implementation of this approach will be worth 5 points of extra credit. This program might be
a helpful model for creating your solution.
Acknowledgement
This assignment was adapted from materials developed by David Evans at the University of Virginia.