Task: Mini Shell
As you might remember, to create a new process you need to use fork (or clone) and exec system calls. If you don’t, take a look at what happens under the hood when you use system.
Enter the labs/lab-07/tasks/mini-shell directory, open the support/src folder and go through the practice items below.
Use the tests/checker.sh script to check your solutions.
./checker.sh
mini_shell: ls ................ passed ... 50
mini_shell: pwd ................ passed ... 25
mini_shell: echo hello ................ passed ... 25
100 / 100
-
With this knowledge in mind, let’s implement our own mini-shell.
Start from the skeleton code in
mini_shell.c. We’re already running our Bash interpreter from the command-line, so there’s no need toexecanother Bash from it.Simply
execthe command.So we need a way to “save” the
mini_shellprocess beforeexec()-ing our command. Find a way to do this.Hint: You can see what
sleepydoes and draw inspiration from there. Usestraceto also list the calls toclone()performed bysleepyor its children. Remember whatclone()is used for and use its parameters to deduce which of the two scenarios happens tosleepy.