进程与进程调度.doc_第1页
进程与进程调度.doc_第2页
进程与进程调度.doc_第3页
进程与进程调度.doc_第4页
进程与进程调度.doc_第5页
免费预览已结束,剩余1页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

实验编号: 四川师大 实验报告 2012年 11 月 12 日计算机科学学院 2010 级 1 班 实验名称: 姓名: 蒋涛 学号: 2010110112 指导老师:张莹实验七 进程与进程调度1. 目的要求(1) 学习和掌握fork等系统调用的基本使用方法。(2) 理解进程概念和进程状态切换。(3) 理解进程创建、等待、终止和替换的过程。2. 实验内容l 使用vi将程序清单7-1输入、编译并运行,其执行结果是:_l 通过分析程序清单7-1的执行结果,总结fork调用返回过程。当调用fork函数的时候,将产生一个子进程,这个时候子进程将父进程的代码,数据,堆栈等内容复制一份,和父进程抢占cpu,如果子进程抢占了cpu,那么fork的返回值为0,所以和输出pid=0,child=6375,等待子进程运行完毕,父进程就从将才子进程运行的位置开始运行,并且fork将返回子进程的pid,所以输出pid=6376 parent=7375 l 使用vi将程序清单7-2输入、编译并运行,其执行结果是:_l 通过分析程序清单7-2的执行结果,总结父子进程之间的关系。从fork函数创建子进程后,子进程将从父进程那里复制代码段,数据,堆栈各自运行的数据互相不影响_ l 使用vi将程序清单7-3输入、编译并运行,其执行结果是: _l 分析程序清单7-3执行结果输出的原因。当i=0时,创建子进程子进程先执行,打印son=0,接着i=1,son=0创建子进程并打印son=1;son=1先执行,i=2时创建son=2,打印son=2并退出;在i=1时的son这时打印father=2并退出;i=1时,son=1这个子进程 l 使用vi将程序清单7-4输入、编译并运行,其执行结果是: _l 使用vi将程序清单7-5、7-6输入、编译并运行,其执行结果是: _l 比较两个程序执行结果,说明其区别产生的原因。exit函数在退出的时候会把buf缓冲区的内容写回文件中,但是_exit函数不会把buf缓冲区的内容写回文件_ 3. 主要仪器设备及软件(1) 硬件:计算机、网络(2) 软件:VMWare workstation、RedHat 9.04. 附录:程序清单(1) 7-1#include unistd.h#include stdio.hint main(int argc,void * argv) int pid = fork(); if (pid = 0) printf(return pid = %d,child id = %dn,pid,getpid(); else printf(return pid = %d,parent id = %dn,pid,getpid(); exit(0);(2) 7-2#include #include #include err_exit.hint global = 5;int main(void)pid_t pid;char *string = these are values before fork:;int local = 10;printf(before fork * * *nn);if(pid = fork()0)err_exit(fork error);if(pid = 0)string = I am child.;printf(nMy pid is %sn,string);printf(“global = %dn local = %dn,global,local);global+;elsestring = I am parent.;printf(nMy pid is %sn,string);printf(“global = %dn local = %dn,global,local);local+;printf(%sn Now,global = %d,local = %dn,string,global,local);exit(EXIT_SUCCESS);(3) 7-3#include “stdio.h”#include “stdlib.h”int main() int i; for( i= 0; i 3; i+) int pid= fork(); if(pid= 0) printf(sonn); else printf(fathern); return 0;(4) 7-4#include “stdio.h”#include “stdlib.h”#include “sys/types.h”#include “signal.h”main()pid_t pid;int status,i;if(fork()= =0)printf(“This is the child process .pid =%dn”,getpid();exit(5);elsesleep(1);printf(“This is the parent process ,wait for child.n”;pid=wait(&status);i=WEXITSTATUS(status);printf(“childs pid =%d .exit status=dn”,pid,i);(5) 7-5#include“stdlib.h”main()printf(output begin);printf(c

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论