資訊人筆記

Work hard, Have fun, Make history!

使用者工具

網站工具


course:nctu-高等unix程式設計:hw3

高等UNIX程式設計:作業三

0x00 前言


0x01 作業描述

本次作業主要為練習 process relationships, descriptors, signals simple IPC(Inter-Process Communication) with pipes

需要實作一個 Simple Shell,包含以下要求

  1. [basic] Execute a single command.
  2. [basic] Properly block or unblock signals.
  3. [basic] Replace standard input/output of a process using the redirection operators (< and >).
  4. [basic] Setup foreground process group and background process groups.
  5. [basic] Create pipeline for commands separated by the pipe operator (|), and put the commands into the same process group.
  6. [optional] Manipulate environment variables: provide commands like export and unset to add and remove environment variables, respectively.
  7. [optional] Expand of the * and ? operators.
  8. [optional] Job control: support process suspension using 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

需要提供 MakefileREADME

0x02 範例程式

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.


0x03 參考資料

course/nctu-高等unix程式設計/hw3.txt · 上一次變更: 127.0.0.1