- Arch Linux KDE
- 把
my_shell.c
與child.c
自動化編譯成my_shell
與child
- 命令列提示
1092926 ms>
- 輸入
hello
,印出Parent process(**pid**) is int the FOREGOUND
child
, 在前景執行child
執行檔(parent process
會 waitchild process
)child &
,在背景執行child
執行檔exit
,結束程式
- 函式
forkToChild(pid_t pid[], int status)
- 判斷
fork()
有沒有成功 status
為1
在背景執行;0
則是在前景執行
- 判斷
cleanProcess(pid_t pid[], int size)
- 將所有在背景執行的
process
都kill
掉
- 將所有在背景執行的
- 前景執行
- 命令列提示
1092926 child>
- 輸入
hello
,印出Child process(**pid**) is in the FOREGROUND.
exit
,結束程式
- 命令列提示
- 背景執行
- 沒有輸入
- 印出
Child process(**pid**) is in the BACKGROUND.
- 間隔
10
秒
- 命令列提示
abc_fg >
- 輸入
^Z
會跳出,但不停止程式hello
印出Hello, ForeGround!
exit
結束程式
- 沒有輸入
- 一直印出
abc_bg > Hello, BackGround!
並間隔 20 秒再印下一次
- 命令列提示
my_shell >
- 輸入
abc_fg
執行abc_fg.sh
abc_bg
執行makeBackgroundProcess
在背後執行
abc_bg.sh
並記錄該 process 的pid
在pid.txt
中hello
印出Hello, MyShell!
exit
刪掉背景執行的abc_bg.sh
沒有的話直接退出