fork() 的执行顺序?
fork() sequence of execution?
int main () {
fork ();
fork ();
fork ();
pf (" hi\n");
}
"hi" 会打印多少次?
fork() 的执行顺序是什么?
os:linuxcompiler:gcc
问题一:"hi"会打印多少次?
Due to first Fork
|
-------------------------
| |
Due to second fork Due to second fork
| |
---------------------- ----------------------------
| | | |
Due to 3rd fork Due to 3rd fork Due to 3rd fork Due to 3rd fork
| | | |
------------------ --------------- ---------- ------------
| | | | | | | |
process-1 process-2 process-3 process-4 pr-5 pr-6 process-7 process-8
所以
如果所有 fork
顺利,那么总共创建 8 个进程,因此输出
中将有 8 个或更少的 hi
问题2: fork() 的执行顺序是什么? os:linuxcompiler:gcc
无法保证哪个进程将首先被调度,哪一秒被调度。
这一切都取决于调度程序。
int main () {
fork ();
fork ();
fork ();
pf (" hi\n");
}
"hi" 会打印多少次? fork() 的执行顺序是什么? os:linuxcompiler:gcc
问题一:"hi"会打印多少次?
Due to first Fork
|
-------------------------
| |
Due to second fork Due to second fork
| |
---------------------- ----------------------------
| | | |
Due to 3rd fork Due to 3rd fork Due to 3rd fork Due to 3rd fork
| | | |
------------------ --------------- ---------- ------------
| | | | | | | |
process-1 process-2 process-3 process-4 pr-5 pr-6 process-7 process-8
所以
如果所有 fork
顺利,那么总共创建 8 个进程,因此输出
问题2: fork() 的执行顺序是什么? os:linuxcompiler:gcc
无法保证哪个进程将首先被调度,哪一秒被调度。 这一切都取决于调度程序。