当前位置:首页 > 4444临时 > 正文内容

[16][9][单选]对于如下C语言程序

4444临时5个月前 (02-02)

int main(

{

pid_t pid;

int a;

pid = fork(;

if(pid == 0


printf("This is the son process, a=%d\n", ++a;

else


printf("This is the dad process, a=%d\n", --a;

}

在UNIX操作系统中正确编译链接后执行,其运行结果是

This is the son process, a=11

This is the dad process, a=9

This is the son process, a=11

This is the dad process, a=9


答案

This is the son process, a=11

This is the dad process, a=9


解析

从调用fork(后就有两个进程在执行,一个是调用fork(后创建的子进程,另一个是父进程。子进程执行++a所以a=11,父进程执行--a所以a=9,故选A选项。

【涉及考点】

第3章 进程线程模型


转载请注明出处。

本文链接:http://pythonopen.com/?id=6463

相关文章

[12][20][单选]下列关于文件系统中文件的描述中,哪一个是正确的

构成文件内容的基本单位为信息项文件的内容没有顺序关系文件内容都是由操作系统程序并使用的用户需要关注文...

[12][22][单选]下列关于实现创建文件操作的描述中,哪一个是错误的

创建文件操作完成后,该文件得到一个新的文件控制块FCB创建文件操作完成后,操作系统给该文件分配一定的...