
- 當我們開啟 Shell 出現
$符號時,系統就已經開啟了一個 Process(在螢幕上輸出$屬於 STDIN) - 當我們打
$ ls後,Shell Process 會先呼叫 fork 這個 system call,這個函數會創造一個 child process 並且其會繼承 parent process 的進程(cwd、file descriptor、Ulimit),但會有獨立的 PID - 這個子 process 會呼叫
execve(),清空之前執行的指令及 cache 等,並且開始執行新的程序內容 - 執行完後會終止 process 並讓 parent process 停止 wait
File I/O

related note: D-SP-Ch3a-UnbufferedIO
child process 會完整複製 parent process 的 file desc. table,並且這個 file desc. table 的每一項都指向和 parent process 相同的 open file table 條目
所以
- 更改 child process 的 file desc. table 不會影響到 parent process 的 file desc. table
- 因為 child process 和 parent process 的 file desc. 指向同一個 open file 條目,所以在 child process 的操作會影響到對應的 open file table 條目