本次作業主要為練習 process relationships, descriptors, signals 和 simple IPC(Inter-Process Communication) with pipes
需要實作一個 Simple Shell,包含以下要求
export
and unset
to add and remove environment variables, respectively.*
and ?
operators.Ctrl-Z
, and jobs
, fg
and bg
command.not allowed to invoke commands using other shells directly in your program via functions like system() or other equavalent implementations in your program
需要提供 Makefile 和 README
Execute a single command:
shell-prompt$ ls -la
Properly block or unblock signals: Sending SIGINT or SIGQUIT should not terminate the current running shell.
shell-prompt$ sleep 10
Run the above command and send signals like SIGINT or SIGQUIT to the correct process (before the process terminates). Note, this test may only work if you have already properly set the foreground process group.
Replace standard output of a process:
shell-prompt$ ls -la > /tmp/x
You will be not able to see the output, but the output is written to the file /tmp/x.
Replace standard input of a process:
shell-prompt$ cat < /etc/passwd
Setup foreground process group and background process groups:
shell-prompt$ less /etc/passwd
Create pipelines:
shell-prompt$ cat /etc/passwd | cat | less
Put processes into the same process group:
shell-prompt$ ps -o pid,sid,pgid,ppid,cmd | cat | cat | tr A-Z a-z
Processes generated by a single command should be in the same process group.
Manipulate environment variables:
You can use the relevant commands to add and remove environment variables and then use the printenv
command to list all the available environment variables.
Expand * and ? characters:
shell-prompt$ ls *
If you see an error message like ls: cannot access *: No such file or directory
, you did not properly implement the filename expansion feature.
Job control:
You should be able to put a process (or a group of processes) into background if an & operator is appended to a command. You should also implement jobs
, fg
and bg
command to change the current foreground process group and continue the execution of a stopped process group.