对于如下C语言程序 int main() { pid_t pid; int x=1; pid=fork(); if(pid= =0) printf("I am the child process,x=%d\n

admin2020-03-31  38

问题 对于如下C语言程序
  int main()
  {
    pid_t pid;
    int x=1;
    pid=fork();
    if(pid= =0)
    printf("I am the child process,x=%d\n",  + +x);
    else
    printf("I am the parent process,x=%d\n",- -x);
  }
  在UNIX操作系统中正确编译链接后,其正确的运行结果是(    )。

选项 A、I am the child process,x=2
    I am the parent process.x=0
B、I am the child process,x=2
C、I am the parent process,x=0
D、I am the parent process,x=2
    I am the child process.x=0

答案A

解析 计算机程序设计中的fork()函数的返回值:若成功调用一次则返回两个值,子进程返回0,父进程返回子进程标记;否则,出错返回-1。运行后的输出为I am the childprocess,x=2 I am the parent process,x=0。故本题答案选择A选项。
转载请注明原文地址:https://kaotiyun.com/show/6u8Z777K
0

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