Question #1 (20 pts): ics412sh Version 1
Implement a Shell, ics412sh_v1, that prints a prompt to the screen,
accepts a command typed by the user, executes that command, and prompts
the use again. The Shell provides the three following built-in
commands:
Important: The Shell should print out error messages when the command doesn't exist, or when arguments to built-in commands are illegal. (System programs will deal with errors in their arguments themselves.)
Here is a transcript of an interaction with ics412sh_v1 (user input is in bold):
ics412sh% pwdTo get you started, and so that you don't struggle with commandline parsing, here is a starting point: ics412sh_skeleton.c. You can compile this program and run it. It doesn't execute the commands or handles the ^C, but it parses the commandline and prints out their arguments. Parsing is done via a single call to function parse_commandline(char *commandline, char ***args1, char ***args2, char **output), which is documented in the source code. (For this question, you do not need to worry about args2 or about output.)
/home/casanova/ics412/pa2
ics412sh% ls
ics412sh_v1.c Makefile
ics412sh% cd
ics412sh% pwd
/home/casanova
ics412sh% cd ..
ics412sh% pwd
/home
ics412sh% sleep 10
^C ics412sh% logout
Question #2 (5 pts): ics412sh Version 2
Implement a more evolved Shell, called ics412sh_v2, which extends
the Shell from Question #1 as follows. The user must be able to stop
the execution of a running system programs by hitting ^C. The Shell
itself must not exit if the user types ^C. (Typing ^C sends a SIGINT
signal to the process.)
Question #3 (10 pts): ics412sh Version 3
Implement a more evolved Shell, called ics412sh_v3, which extends
the Shell from Question #2 by allowing the user to do pipes:
ics412sh% pwdFunction parse_commandline() will do the parsing of the commandline for you, and place the arguments to the second command in a NULL-terminated arrays (read the documentation of parse_commandline()).
/home/casanova/ics412/pa2
ics412sh% ls | grep ke
Makefile
ics412sh% exit
Question #4 (10 pts): ics412sh Version 4
Implement a more evolved Shell, called ics412sh_v4, which extends
the Shell from Question #3 by allowing the user to redirect output to a file:
ics412sh% ls > somefileFunction parse_commandline() will do the parsing of the commandline for you, and place the name of the file to which output should be redirected in a string (read the documentation of parse_commandline()).
ics412sh% ls | grep ke > someotherfile
ics412sh% cat someotherfilels
Makefile
ics412sh% exit
Question #5 (10 pts): ics412sh Version 5 [EXTRA CREDIT]
Implement a more evolved Shell, called ics412sh_v5, which extends
the Shell from Question #4 by allowing the user to start jobs in the background,
kill them, and wait for them:
ics412sh% ls -R / > foo &
job [1]
ics412sh% ls -R /home/ > foo2 &
job [2]
ics412sh% sleep 5 &
job [3]
ics412sh% sleep 10
[3] Done
ics412sh% jobs
[1] Running
[2] Running
ics412sh% kill 1
[1] Killed
ics412sh% kill 3
No such job
ics412sh% fg 2