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

admin2020-03-31  45

问题 请分析下列程序。
  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 Iam in parent processo故本题答案选择A选项。
转载请注明原文地址:https://kaotiyun.com/show/7M8Z777K
0

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