Project Background
One of the fundamental functionalities of Linux (and Linux-like OSs) is the ability to pipe commands. When the | character is used in a shell between two commands, the shell takes the output from the first command and “pipes” it to the second command as the input. You can try it yourself! If you run the command ls -la / | grep tmp on systems1, you should be able to see only the tmp directory output from ls -la. This is because you gave grep, a common search tool, the output of ls -la directly.
Project Summary
For this project a simple program that will act as a shell is written. The program should display a command prompt and read in a command line from the user, your shell must support basic piping like the unix shell (both sequential and redirecting output), and should be able to handle CTRL-C and CTRL-Z signals.
Some Requirements:
- Handle [$ command] (run command, with stdin and stdout connected to their usual files, must additionally output [pid:%d status:%d\n], then continue).
- Handle [$ command1 | command2] (run command1 as in #1, but redirects the output of command1 as input to command2, then continue).
- Handle [$ command1 ; command2] (run command1 as in #1, wait for it to finish, and then run command 2 as in #1, then continue).
- Handle SIGINT - Generated by Ctrl-C (print “caught sigint” and then continue)
- Handle SIGTSTP - Generated by Ctrl-Z (print “caught sigstp” and then continue)
Topics Learned Upon Completion
- How to use system calls in C (Specifically execv() and fork())
- How to add signal handlers in C
- Nuances of forking and running different programs in child processes