gpt4 book ai didi

c - fork 及其功能?

转载 作者:行者123 更新时间:2023-12-04 11:27:51 26 4
gpt4 key购买 nike

我有以下代码,并被问到“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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com