[7][9][单选]对于如下 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操作系统中正确编译链接后,其正确的运行结果是
I am the child process, x=2 I am the parent process, x=0
I am the child process, x=2
I am the parent process, x=0
I am the parent process, x=2 I am the child process, x=0
答案
I am the child process, x=2 I am the parent process, x=0
解析
计算机程序设计中的fork()函数的返回值:若成功调用一次则返回两个值,子进程返回0,父进程返回子进程标记;否则,出错返回-1。
转载请注明出处。
![[7][30][单选]某计算机系统中共有 3 个进程 P1、P2 和 P3,4 类资源 r1、r2、r3 和 r4。](http://pythonopen.com/zb_users/upload/2025/01/202501271737983564818658.png)
