我不知道fork中首先执行的是什么。例如我有这样的代码:
int main() {
int n = 1;
if(fork() == 0) {
n = n + 1;
exit(0);
}
n = n + 2;
printf(“%d: %d\n”, getpid(), n);
wait(0);
return 0;
}
这会在屏幕上打印什么?
1: 3
0: 4
或
0: 4
1: 3
最佳答案
没有具体说明。由操作系统调度程序决定首先调度哪个进程。
After a fork(), it is indeterminate which process—the parent
or the child—next has access to the CPU. On a multiprocessor system,
they may both simultaneously get access to a CPU.
关于c - 在 fork() 程序中首先执行什么? parent 还是 child ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17388621/