本作業實作一個簡易 Shell 程式。支援 built-in 指令與 external command,並實作 I/O redirection 以及 pipe 。
- 實作於
builtin.c中的cd() - 支援輸入路徑作為參數,未輸入時顯示錯誤訊息
- 實作於
spawn_proc()(shell.c) - 使用
fork()建立 Child Process - Child Process 中使用
execvp()執行外部指令 - Parent Process 使用
waitpid()等待完成
- 實作於
redirection()(shell.c) - 輸入檔案使用
open()並以dup2()取代stdin - 輸出檔案使用
open()並以dup2()取代stdout
- 實作於
fork_cmd_node()函式 - 每個指令透過
spawn_proc()呼叫