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

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

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

int main( {    pid_t pid;    int a = 5;    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 = 4

This is the dad process, a = 6

This is the son process, a = 4

This is the dad process, a = 4

This is the son process, a = 5

This is the dad process, a = 5


答案

This is the son process, a = 5

This is the dad process, a = 5


解析

上述 C 语言程序中 fork 函数调用后返回两个值,父进程返回子进程标记,子进程返回 0。对于子进程,a 的值不变,对于父进程,a 的值也不变。故运行结果为 This is the son process, a = 5 和 This is the dad process, a = 5。选项中没有该结果,可能原题目有误,按照常规思路分析应选 A 选项。涉及考点为第 2 章进程管理。


转载请注明出处。

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

相关文章

[12][3][单选]处理器中对用户可见的存储器是

程序状态字寄存器数据寄存器程序计数器指令寄存器答案数据寄存器解析处理器一般包括两类寄存器:一类称为用...

[12][4][单选]中断是指CPU对系统中或系统外发生的异步事件的响应,中断源是指

引起中断的那些事件中断控制器向处理器发出的信号正在执行的程序的暂停点使处理器暂停当前程序而去处理中断...

[12][8][单选]当使用进程创建原语创建进程时,下列哪一个选项表示创建的顺序是正确的

申请PCB,填写PCB,放入运行队列申请PCB,填写PCB,放入就绪队列申请PCB,申请内存,填写P...

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

int main({pid_t pid;int a = 1;pid = fork(;if(pid =...

[12][10][单选]对于如下C语言程序

void *th(void *arg{printf("Hello World";...

[12][11][单选]两个相互不感知完全不了解其他进程是否存在的进程,其潜在的控制问题是

两个进程通过通信方式协作,但可能造成互斥、死锁或饥饿两个进程相互不等待,不协作,但可能造成互斥或死锁...