我有以下代码,并被问到“A”、“B”、“C”、“D”、“E”将被打印多少次
fun() {
printf("A");
fork();
printf("B");
if (fork() != 0) {
printf("C");
fork();
printf("D");
}
printf("E");
}
应该是:
A
A
B
E
我不确定我上面的回答是否正确? if(fork() !=0 )
这行是做什么的?
最佳答案
来自documentation :
On success, the PID of the child process is returned in the parent, and 0 is returned in the child. On failure, -1 is returned in the parent, no child process is created, and errno is set appropriately.
关于c - fork 及其功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13792363/