CS:APP Shell, my attempt at a practice assignment from
"Computer Systems: A Programmer's Perspective" to implement a rudimentary Unix
shell, which can fork child processes to run commands, intercept Ctrl+C and Ctrl+Z
signals to forward to child processes, run processes in the background by appending
a &
to the command, and list and kill jobs. Aside from some clunkiness I hope
to come back and amend regarding the interaction between the user input prompt and
printed information from incoming signals, I think I dare say for a textbook assignment
my implementation is Decent, given that the book and assignment didn't quite aim to produce
a real-world robust shell so much as a seed for what one might look like. (I also
went out of my way to figure out Unix methods for getting the username and hostname
for the prompt!)
I also used the assignment as an excuse to play with some features of the C23
standard, e.g. attributes and nullptr
.
Log from a simple example session:
./csh
joculatrix@shagohod> ./scripts/sleep.sh 50 &
[0] 23285
joculatrix@shagohod> ./scripts/sleep.sh 50 &
[1] 23287
joculatrix@shagohod> jobs
JOB PID STATUS COMMAND
0 23285 Running ./scripts/sleep.sh 50 &
1 23287 Running ./scripts/sleep.sh 50 &
joculatrix@shagohod> kill %1
joculatrix@shagohod>
[1] killed ./scripts/sleep.sh 50 &
joculatrix@shagohod> kill 23285
joculatrix@shagohod>
[0] killed ./scripts/sleep.sh 50 &
joculatrix@shagohod> jobs
JOB PID STATUS COMMAND
joculatrix@shagohod> quit