操作系统惠普测试171+实验2-进程的创建与控制实验(1)_第1页
操作系统惠普测试171+实验2-进程的创建与控制实验(1)_第2页
操作系统惠普测试171+实验2-进程的创建与控制实验(1)_第3页
操作系统惠普测试171+实验2-进程的创建与控制实验(1)_第4页
免费预览已结束,剩余1页可下载查看

下载本文档

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

文档简介

1、操作系统原理A实验报告学生姓名:陶浩学号:22班级:惠普测试171实验名称:实验2进程的创建与控制实验指导教师:葛艳(一)进程的创建一、实验目的1. 加深对进程、进程树等概念的理解。2. 进一步明确进程和程序的区别。3. 理解进程并发执行的实质。4. 掌握Linux系统中进程的创建方法及并发执行情况。二、实验内容1. 运行给定参考程序(P31页),把运行结果截图。分析fork0创建子进程的要点。2. 运行下面的程序,把运行结果截图。分析printf (” fork 1 ,PID=%dn“,getpidO); ”为什么会被执行两次。mainO int pl, p2;pl=fork();taoha

2、otaohao-PC: -/Desktop +r*fork1.c*/include include include include include iain()int p,x,ppid,pid;x=0;p-fork();if(p0)/*如果是父进程粉 wait(O); /父进程等待子进程运行结束 printf(parent output x=%dnw,+x); pid=getpid();/茯取进程自身的ID号printf(”Thi id number of parent is:pid=%dnHrpid); printf(In the parent: p=%dn/p);else/*如果是子进程*

3、/printf(child output x=%dnH r+x); pid=getpid();printf(”Thi id number of child is:pid=%dnjpid); ppid=getppid();/获取父进程的ID号print+(Thi id number of parent is:ppid=%dn,ppid); printf(In the child: :p=%dn,p);taohao(a)taohao-PC: “/Desktoptaohaotaohao-PC:/Desktop$ gcc forkl.c -o forkltaohaotaohao-PC: -*/Desk

4、top$ /forkl child output x=1Thi id Thi id In the paren t Thi idnumber number child : output numberof child is:pid=6279 of parent is:ppid=6278 :p=0x=1of parent is:pid=6278In the parent: p=6279taohaotaohao-PC:-/Desktop$:行下面的程序,把运行结果截图。分析“printf(” fork L PID=%dn JgetpidO); ”为什么会 被执行两次。taohaotaohao PC:/

5、Desktop/osLear ning+includeWincludefincludeinclude0)p2=fork();if(p2=0)printf(fork 2/PID=%dn fgetpid();elseprintf(fork 3/PID=%dnn,getpid(); sleep(50);th.c11 17L. 333C鼻taohaotaoha q PC: -/Desktop/osLeami ng+taohaotaohao-PC:-/Desktop/osLearning$ th.c -o th taohaotaohao-PC:-/Desktop/os Lea rning$ /th fo

6、rk 1rPID=10821 fork 1rPID=lO822 fork 3rPID=10822 fork 2rPID=10823分析:Pl=fork0 :生成一个父进程和一个子进程,父进程和子进程重复执行所以 printf (w fork L PID=%dn getpidO);执行了两次。3.编写一段程序,使用系统调用fork0创建一个子进程。子进程输出fork。返回值,获 取并输出父进程的ID号。父进程等待子进程运行结束后,输出forkO返回值,获取并输出 自己的ID号。(要求把程序调试和运行结果截图)taohaotaoha o PC: /Desktop/osLearning十#inclu

7、de#ir)clude#include #include #includevsys/wait.h main()int pppichpid; p=fork();if(p0) wait(O); pidgetpid(); printfC父进程自身的 ID:%dnH rpid); printf ( fork 返回值:%dnM ,p);else printfC子进程輸出fo返回值:%dnn ,p); ppid=getppid();printf (输出父进程的 ID号:%dnH rppid);forkS.c11 21Lr 439Ctaohaotaohao-PC: -/Desktop/osLear ning +taohaotaohao-PC:-/Desktop/osLearning$ g+ fork3 c -o fork3 taohaotaohao-PC;-/Desktop/osLearning$ ./fork3 子进程输出fork返回值:0 输出父进程的ID号:19051 父进程自身的ID:19051fork返回值:19052 taohaotaohao-PC:-/Desktop/osLearningl |关键词:进程:进程就是指一个程序的运行过程,进程和线程类似有着三种状态,就绪状态、运行状态 和阻塞。进程由

温馨提示

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

评论

0/150

提交评论