请分析下列程序。 int main() { printf("This is in main program"); if(fork()==0) printf("I am in child process"); else

admin2019-05-20  53

问题 请分析下列程序。
  int main()
  {
    printf("This is in main program");
    if(fork()==0)
    printf("I am in child process");
    else
    printf("I am in parent:process");}
  程序正确运行后结果:是(    )。

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

答案A

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

最新回复(0)