[3][9][单选]请分析以下程序。
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()); }
那么,该程序正确运行后的结果是
I am the child process, my process ID is 3744 I am the parent process, my process ID is 3987
I am the child process, my process ID is 3744
I am the parent process, my process ID is 3987
不输出任何信息
答案
I am the child process, my process ID is 3744 I am the parent process, my process ID is 3987
解析
计算进程设计中的 fork()函数调用返回值:若成功调用,一次返回两个值,子进程返回 0,父进程返回子进程标识。故输出结果为 I am the child process, my process ID is 3744
I am the parent process, my process ID is 3987 选项内容。涉及考点为第 3 章进程线程模型。转载请注明出处。