(完整word版)操作系统实验报告-观察进程的并发性.pdf
《(完整word版)操作系统实验报告-观察进程的并发性.pdf》由会员分享,可在线阅读,更多相关《(完整word版)操作系统实验报告-观察进程的并发性.pdf(8页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、计算机操作系统实验报告1 评语:课中检查完成的题号及题数:课后完成的题号与题数:成绩:指导教师:实验报告一实验名称:观察进程的并发性日期:2011.5.7 班级:学号:姓名:一、实验目的:通过创建子进程,观察父子进程的并发执行过程,区别顺序执行和并发执行;明确进程和程序的区别;加深对操作系统进程概念和进程并发特性的理解。二、实验内容:进程的创建。编制一段程序,使用系统调用fork()创建两个子进程,在此程序运行时,系统中就有一个父进程和两个子进程在活动。让每一个进程在屏幕上显示一个字符:父进程显示字符 a,两个子进程分别显示字符b和子符 c。试观察、记录并分析屏幕上进程调度和并发执行的情况。若
2、在程序中使用系统调用nice()来改变各进程的优先级,观察出现的现象.三、项目要求及分析:为了体现出进程的并发性,首先在父进程创建一个子进程,进程里利用循环方式输出字符“b”,然后在父进程里又创建子进程2,进程 2 里循环输出字符“c”,在父进程里循环输出字符“a”。这样程序运行时,父子进程之间并发执行,并输出相应的字符。对于 nice()函数的应用,我主要是先输出子进程1 的优先级,然后用nice 函数修改子进程的优先级,然后观察运行结果。对于子进程2 也用 nice 函数修改了其优先级,再观察运行结果。四、具体实现:计算机操作系统实验报告2 4.1 流程图4.2 添加函数的代码1)进程之间
3、的并发性#include#include#include#include int main()int i,j,k;int pid=fork();/new first thread if(pid=0)/first thread for(j=0;j0)/main thread int pi=fork();/new second thread if(pi=0)/second thread for(k=0;k0)/main thread for(i=0;i5;i+)printf(main:atti=%dn,i);sleep(1);waitpid(pid,0,0);/wait first thread
4、over waitpid(pi,0,0);/wait second thread over printf(main thread exitrn);exit(0);else/second thread failed perror(function fork()error!rn);exit(1);else/first thread failed perror(function fork()error!rn);exit(1);return 0;2)nice 函数的应用#include 文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7
5、 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6
6、ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档
7、编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7
8、O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H
9、6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9
10、文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10
11、P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9计算机操作系统实验报告4#include#include#include int main()int i,j,k;int oldpri,newpri;int pid=fork();/new first thread if(pid=0)/first thread printf(parentpid is%dn,getppid();oldpri=getpriority(PRIO_PR
12、OCESS,getpid();printf(first thread old priority=%dn,oldpri);newpri=nice(5);printf(first thread new priority=%dn,newpri);for(j=0;j0)/main thread int pi=fork();/new second thread if(pi=0)/second thread nice(2);for(k=0;k0)/main thread for(i=0;i5;i+)printf(main:atti=%dn,i);sleep(1);waitpid(pid,0,0);/wai
13、t first thread over waitpid(pi,0,0);/wait second thread over 文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A
14、8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:C
15、M3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 H
16、W1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV
17、3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码
18、:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7
19、 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9计算机操作系统实验报告5 printf(main thread exitrn);exit(0);else/new thread failed
20、perror(function fork()error!rn);exit(1);else/new thread failed perror(function fork()error!rn);exit(1);return 0;五、调试运行结果:1)进程之间的并发性结果文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编
21、码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O
22、7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6
23、 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文
24、档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P7O7 HW1P1F4C8H6 ZV3A8G8M3X9文档编码:CM3H5Y10P
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 完整 word 操作系统 实验 报告 观察 进程 并发
限制150内