CSCI 320 - Operating Systems & Concurrency

Spring 2019

Rush - the Rust Shell, part 2

Assignment

In this assignment, we continue implementing an interactive Unix shell using the Rust language. Use nix, which is a Rust binding to the basic Unix system calls. Each system call has a corresponding (safe) Rust wrapper. Implement your shell according to the following steps:
  1. 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. This is typically used for long-running programs that perform a lot of computation. It is most often used in conjunction with output redirection, as described in step 2.
  2. If (prior to the & symbol, if present) the line ends with a > symbol that is immediately followed by a string, the command's output goes to the file named by the string. If the file does not exist, it will be created.
  3. 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 input has been redirected by the < symbol, then the leftmost process will receive the input from that file.
  4. If (prior to the first | symbol, or if no pipes are present, prior to the > symbol and & symbols, if present) the line ends with a < symbol that is immediately followed by a string, the command's input comes from the file named by the string. If the file does not exist, the command will be aborted.

Examples

Pseudocode for processing a command

The following pseudocode represents one possible algorithm for processing a command. Feel free to borrow any ideas from this algorithm that you find helpful. Note that redirecting standard output can make debugging difficult; I recommend using eprintln!, which prints to standard error.

Grading

The assignment is worth 30 points: 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.

Acknowledgement

This assignment was adapted from materials developed by David Evans at the University of Virginia.