2011 - 山东农业大学-Linux操作系统(A)及详细答案(DOC)

山东农业大学课程考试专用 得分 四、问答题(共50分) 1、读下面的代码,回答以下问题( 8分) ① 该程序运行时会产生几个进程? ② 输出“A:my pid is…”和输出“B:my pid is…”的进程的亲缘关系如何,为什么? main(){ int a; pid_t pd1,pd2; pid1=fork(); pid2=fork(); if (pid1==0 && pid2>0) printf(“A:my pid is:%d\\n”,getpid()); if (pid1>0 && pid2==0) printf(“B:my pid is:%d\\n”,getpid()); } 2、某管道操作程序的部分代码如下,阅读程序回答下面问题:(10分) ① 程序运行会有怎样的输出?说明你的分析。 ② 请说明系统调用fork( )为什么应该在调用pipe( )前面使用? ③ wait(NULL)的作用是什么?int main(){ int pid_fd[2]; pid_t pid; char buf_f[100]; char* p_wbuf; int r_num; memset(buf_r,0,sizeof(buf_r));//对缓冲区进行初始化 if(pipe(pipe_fd)<0) { printf(“pipe create error\\n”); return -1; } 注:考试期间试卷不允许拆开。 第 5 页 共 10 页 山东农业大学课程考试专用 if((pid=fork())==0){ close(pipe_fd[1]); sleep(2); if((r_num=read(pipe_fd[0],buf_r,100)).0) { printf(“%d numbers read from the pipe is %s\\n”,r_num,buf_r); } close(pipe_fd[0]); exit(0); } else if(pid>0) { close(pipe_fd[0]; if(write(pipe_fd[1],”Hello”,5)!=-1) printf(“parent write1 Hello!\\n”); if (write(pipe_fd[1], “ Pipe”,5)!=-1)//Pipe前有一个空格 printf(“parent write2 pipe!\\n”); close(pipe_fd[1]); sleep(3); wait(NULL); exit(0); } return 0; } 3、简单介绍至少4种进程通信方式。(8分) 4、什么是物理内存空间、虚拟地址空间。简单说明Linux下内存分配和回收的过程。(8分) 注:考试期间试卷不允许拆开。 第 6 页 共 10 页 山东农业大学课程考试专用 5、 Linux的内存管理函数malloc、kmalloc和vmalloc有什么异同。(8分) 6、 系统调用和模块有什么区别?简述添加一个满足自己需求的系统调用的步骤有哪些?(8分) 注:考试期间试卷不允许拆开。 第 7 页 共 10 页 山东农业大学课程考试专用 2010 -2011 学年第 1 学期 《Linux操作系统》A卷答案 课程代码 考试方式 考试时长 分钟 姓名 学号 教学班号 专业 级 班 一、选择题(每题1分,共20分) 1~5 C D A C A 6~10 D D A D B 11~15 B B C C B 16~20 C C B C B 二、应用题(20分) 1、 解释命令功能或根据功能写出命令(5分,每题1分)

>>鐏炴洖绱戦崗銊︽瀮<<
12@gma联系客服:779662525#qq.com(#替换为@)