单选题
1分
请分析以下程序。int main(){pid_t pid;pid = fork();if(pid==0)printf("I am the&n...
请分析以下程序。
int main()
{
pid_t pid;
pid = fork();
if(pid==0)
printf("I am the child process, my process ID is%d\n",getpid());
else
printf("I am the parent process, my process ID is%d\n",getpid());}
那么,该程序正确运行后的结果是
int main()
{
pid_t pid;
pid = fork();
if(pid==0)
printf("I am the child process, my process ID is%d\n",getpid());
else
printf("I am the parent process, my process ID is%d\n",getpid());}
那么,该程序正确运行后的结果是
参考答案: A
参考解析: A【解析】计算机程序设计中的fork()函数。返回值: 若成功调用一次则返回两个值,子进程返回0,父进程返回子进程标记;否则,出错返回-1。假设程序正确运行并创建子进程成功,那么,子进程为0,父进程为进程号,故输出I am the child process, my process ID is 3744
I am the parent process, my process ID is 3987。故选择A选项。