根据以下程序段,分析程序运行后的结果是( )。 int main() {printf("This is in main program"); if(fork()==0) printf("I am in A process"); else

admin2022-06-20  32

问题 根据以下程序段,分析程序运行后的结果是(          )。
int main()
{printf("This is in main program");
if(fork()==0)
printf("I am in A process");
else
printf("I am in B process");}

选项 A、This is in main program I am in A process I am in B process
B、This is in main program I am in A process
C、This is in main program I am in B process
D、This is in main program I am in A process This is in main program I am in B process

答案A

解析 计算机程序设计中的fork()函数的返回值:若成功调用一次则返回两个值,子进程返回0,父进程返回子进程标记;否则,出错返回-1。假设程序正确运行并创建子进程成功,那么,子进程为0,父进程为进程号,因此,输出This is in main program I am in A process I am in B process。因此,本题答案选择A选项。
转载请注明原文地址:https://jikaoti.com/ti/Lyl7FFFM
0

相关试题推荐
随机试题
最新回复(0)