首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
对于如下C语言程序 int main() { pid_t pid; int a=1; pid=fork(); if(pid==0、 pfintf(“This is the son process,a=%d\n”,++a);
对于如下C语言程序 int main() { pid_t pid; int a=1; pid=fork(); if(pid==0、 pfintf(“This is the son process,a=%d\n”,++a);
admin
2021-03-19
27
问题
对于如下C语言程序
int main()
{
pid_t pid;
int a=1;
pid=fork();
if(pid==0、
pfintf(“This is the son process,a=%d\n”,++a);
else
pfintf(“This is the dad process,a=%d\n”,--a);
}
在UNIX操作系统中正确编译链接后,其运行结果为( )。
选项
A、This is the son process,a=2
This is the dad process,a=0
B、This is the son process,a=2
C、This is the dad process,a=0
D、This is the dad process,a=2
This is the son process,a=09
答案
A
解析
函数fork()的作用是通过系统调用创建一个与原来进程几乎完全相同的进程。对于子进程返回标识符0;对于父进程返回子进程的PID。父进程和子进程拥有各自的局部变量a,初始值都为1;所以子进程中PID为0,执行的是第1个printf,由a的值为1,先自增再输出值,可知输出的是This is the son process,a=2;而父进程中PID为子进程的PID,不为0,执行的是第2个printf,由a的值为1,先自减再输出值,可知输出的是This is the dadpFocess.a=0。故本题答案选择A选项。
转载请注明原文地址:https://kaotiyun.com/show/3K8Z777K
本试题收录于:
四级网络工程师题库NCRE全国计算机四级分类
0
四级网络工程师
NCRE全国计算机四级
相关试题推荐
InstructionRegister(IR)isnormallyusedtopointout
在高速并行结构中,速度最慢但通用性最好的是()。
软件工程方法中普遍应用的方法之一是结构化生命周期方法(SLC方法),下述()论述不具有SLC方法的主要特征。
软件开发的结构化生命周期方法将软件生命周期划分成()。
如果你要想成为Internet用户,你必须要找一家能为你提供Internet服务的公司,它的英文缩写是()。
高层服务用户向下一层请求服务时通过服务原语交互,OSI参考模型规定每层使用的四种服务原语是()。
对无向图G(下图),若从顶点V1开始,按深度优先搜索法进行遍历,则可能的访问顺序是()。
下列关于进程的叙述中,正确的是()。
客户端、服务器(C/S)架构和浏览器/服务器(B/S)架是现在常用的两种数据库应用系统架构。关于C/S和B/S架构,下列说法错误的是
随机试题
______isthecapitalofNewZealand.()
梅奥在西方电气公司进行的霍桑试验,在哪个阶段试验得出了企业中存在非正式组织的结论()
男性,56岁,30分钟前心前区压榨样痛,突然出现意识丧失、抽搐,听诊心音消失,脉搏触不到,血压为零,诊断为心脏骤停。下列哪一项不是诊断心脏骤停的必备条件
某年某月某日,某市某化塑制品厂发生火灾,整个厂房被烧毁,造成直接经济损失达127.6万元。当日8时上班后,工人孙某在该化塑制品厂压球车间门口西侧用电焊焊接压模。焊接现场的周围除一条3m宽的通道外,堆满了袋装成品浮球及废料,还有数个装丙酮、乙烷的铁桶
开立证券账户的基本原则为()。
根据调查报告的作用和内容,可将其分为()
态度量表最常测量的两个态度维度包括()。
A、非常骄傲B、很容易遇到C、可以成为师友D、喜欢回忆过去C
GangCrimeLivinginalargeurbancenteroftenequatestolivingnearorwithinthecriminalepicenter,especiallyforinn
Smoking,whichmaybeapleasureforsomepeople,isaserioussourceofdiscomfortfortheirfellows.【C1】______,medicalautho
最新回复
(
0
)