[17][9][单选]对于如下C语言程序
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 dad process, a=11 This is the son 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章 进程线程模型
转载请注明出处。