Shell
Content
Backstory
Important Things to Note
Overview and To-Dos
Starting Your Shell
Interaction Within Your Shell
Built-in Commands
External Commands
Logical Operators
Memory
Background Processes
ps
Redirection Operators
Signal Commands
Grading
Learning Objectives
The learning objectives for Shell are:
Learning How a Shell Works
Fork, Exec, Wait
Signals
Processes
Zombie Processes
Backstory
Important Things to Note
Part 1 due 2024-09-23 23shell.c
Part 2 due 2024-09-30 23shell.c
Well, weʼll keep it short – you got fired from Macrohard. Your boss brought you in for a
code review and was more than disappointed. Apparently, they wanted a C++ style vector:
we didnʼt get the memo. Now, youʼve decided to work for insert hot tech company here,
and you got the job! However, thereʼs a catch - all newhires in insert hot tech company here
apparently have to go through a newcomers test if they want to keep their jobs. The task?
Write a shell. So, youʼre going to drop a shell that is so fancy that your boss will not
just keep you in the company, theyʼll immediately give you a pay raise as well.
The basic function of a shell is to accept commands as inputs and execute the
corresponding programs in response. You will be provided the vector , sstring and
format.h libraries for your use. Hopefully, this will make things right and you can secure
your foothold at insert hot tech company here. Feel free to refer to the Unix shell as a rough
reference.
2024/9/26 21:42 CS 341 · Shell
https://cs341.cs.illinois.edu/assignments/shell#background-processes 1/14Fork Bombs
To prevent you from fork bombing your own VM, we recommend looking into
ulimit
(https://man7.org/linux/manpage.
sT/h.i/sman3/ulimit.3p.html)
will allow you to set a limit for how many times you can fork. Note that
ulimit
(https://man7.org/linux/manpage
iss/ t.e/rmmainn3a/l ulimit.3p.html)
session specific, so you will need to
do it everytime you launch a terminal
add this to your ~/.bashrc file (feel free to look up online how to do so), so that it is
run every time you log in to your VM.
Note that you should give it a more generous amount (say, 100-200), since the terminal will
likely have background processes already running. If you give it too small a limit, you wonʼt
be able to launch anything, and youʼll need to launch a new terminal.
If you happen to fork bomb your CS Cloud VM, please notify course staff in a private post
with your VM number. Note that it may take up to a few hours for us to respond, so try not
to fork bomb your VM.
Plan Before You Start
This assignment marks the beginning of a series of projects where you will be given mostly
blank files without predefined functions to fill in. Most of the remaining MPs will challenge
your design skills to create interesting utilities. Therefore, it is important that you read the
entirety of the documentation (including part 2), as well as the header files to get a
clear idea on what needs to be done. A few reminders about good coding and developing
practices that will really help you in the rest of the semester:
List down the features that you need to implement, as well as the gotchas. Make a todo
list to ensure you donʼt miss out anything.
Plan out the entirety of your assignment. Create a skeleton of how your entire code
will look like. This will prevent you from needing to restructure your entire code to add
in a single new feature.
Ensure that you fully understand the system calls/library functions youʼre using - the
parameters, the return values, the possible errors, the gotchas and notes.
Structure your code into modular functions. You do not want to debug a 1500 line
while loop within main .
Work incrementally. Implement a feature, test, debug, move on.
Good naming and spacing will make your code much more readable.
Try putting TODO comments in unfinished portions of your code. They are
automatically highlighted in many text editors, which alerts you to incomplete code.
Do Not Use
system
(https://man7.org/linux/manpages/./man3/system.3p.html)
Since
a learning objective of this assignment is to use the fork-exec-wait pattern, if you use
system
(https://man7.org/linux/manpage,
sy/o.u/ wmailnl 3a/ustoymstaetimc.a3llpy. fhatilm tlh)is MP.
Input Formatting
Do not worry about irregular spacing in command inputs (i.e. extra whitespace before
and after each token). This is considered undefined behavior and will not be tested. You are
free to make your code as robust as you want, but we will only test the basic cases without
irregular spacing (unless specified).
2024/9/26 21:42 CS 341 · Shell
https://cs341.cs.illinois.edu/assignments/shell#background-processes 2/14Overview and To-Dos
Starting Your Shell
Output Formatting
Since this MP requires your shell and the programs you launch to print a variety of things
like output messages and error messages, we have provided you with our own highly
customized formatting library. You should not be printing out to
stdout
(https://man7.org/linux/manpage
asn/d./ man3/stdout.3p.html)
stderr
(https://man7.org/linux/manpage
ast/ .a/ll;man3/stderr.3p.html)
instead, all output and errors should be printed using the functions provided in format.h .
In format.h you can find documentation about what each function does, and you should
use them whenever appropriate.
If you place print statements in your debugging code, please remember to remove them
before autograding, or use the #define DEBUG block to place your print statements.
Note: donʼt worry if you donʼt use all of the functions in format.h , but you should use
them whenever their documented purpose matches the situation.
Flush Before Forking
Ensure that you
fflush
(https://man7.org/linux/manpage
osu/.tp/umta fnil3e/ hfafnlduslehs. b3pe.fohrtem flo)rking. See
section 2.5.1 of the Open Group Base Specifications
(https://pubs.opengroup.o rfgo/ro mnloinrep inufbosr/m96at9io9n9 1o9n7 w99hy/f uthnicst iosns/V2_chap02.html#tag_15
necessary.
The shell is responsible for providing a command line for users to execute programs or
scripts. You should be very familiar with
bash
(https://man7.org/linux/manpag
beys /n.o/wm,a wn1h/icbha swhil.l 1b.eh tthmel )basis for your own
shell. This is a 2 week MP, and the features you will need to implement are as follows:
Part 1
Starting up a shell
Optional arguments when la