![实验8Linux进程管理_第1页](http://file4.renrendoc.com/view11/M03/10/0B/wKhkGWVuqHmAEm1LAACZG0KMHlA032.jpg)
![实验8Linux进程管理_第2页](http://file4.renrendoc.com/view11/M03/10/0B/wKhkGWVuqHmAEm1LAACZG0KMHlA0322.jpg)
![实验8Linux进程管理_第3页](http://file4.renrendoc.com/view11/M03/10/0B/wKhkGWVuqHmAEm1LAACZG0KMHlA0323.jpg)
![实验8Linux进程管理_第4页](http://file4.renrendoc.com/view11/M03/10/0B/wKhkGWVuqHmAEm1LAACZG0KMHlA0324.jpg)
![实验8Linux进程管理_第5页](http://file4.renrendoc.com/view11/M03/10/0B/wKhkGWVuqHmAEm1LAACZG0KMHlA0325.jpg)
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
《Linux操作系统》实验报告(实验名称:实验八Linux进程管理)专业计算机科学与技术班级计科一班学号202111107013学生姓名郭建杰指导老师黄萍攀枝花数计学院2023年5月7日一、实验目的加深对进程概念的理解,明确进程与程序的区别;进一步认识并发执行的实质掌握进程管理二、实验内容进程创建进程控制三、实验要求【任务1:】进程创建编写一段程序,使用系统调用fork()创建两个子进程。当此程序运行时,在系统中有一个父进程和两个子进程活动。让每一个进程在屏幕上显示一个字符:父进程显示“a“;子进程分别显示字符”b“和字符“c”。观察记录屏幕上的显示结果,并分析原因。【任务2:】进程控制修改已编写的程序,将每一个进程输出一个字符改为每一个进程输出一句话,再观察程序执行时屏幕上出现的现象,并分析原因。【任务3:】进程同步父进程从终端读取要执行的命令,并交给子进程执行。父进程等待子进程结束,并打印子进程的返回值。
提示:从终端读取要执行的命令可用fgets()实现。四、实验结果1.编写一段程序,使用系统调用fork()创建两个子进程。当此程序运行时,在系统中有一个父进程和两个子进程活动。让每一个进程在屏幕上显示一个字符:父进程显示“a“;子进程分别显示字符”b“和字符“c”。观察记录屏幕上的显示结果,并分析原因。#include<stdio.h>#include<stdlib.h>#include<unistd.h>intmain(){pid_tpid1,pid2;pid1=fork();pid2=fork();if(pid1<0||pid2<0){perror("forkerror");}if(pid1==0){printf("pid1=b\n");}else{printf("fatherpid=a\n");}if(pid2==0){printf("pid2=c\n");}else{printf("fatherpid=a\n");}return0;}2.修改已编写的程序,将每一个进程输出一个字符改为每一个进程输出一句话,再观察程序执行时屏幕上出现的现象,并分析原因。#include<stdio.h>#include<stdlib.h>#include<unistd.h>#include<sys/types.h>intmain(intargc,char*argv[]){pid_tpid1,pid2,ppid;printf("boforefork\n");pid1=fork();if(pid1==0){printf("successdthisisasonprocessb\n");}if(pid1<0){printf("fork\n");}else{printf("thisisfatherprocessa\n");}pid2=fork();if(pid2==0){printf("successdthisisasonprocessc\n");}else{printf("fork\n");}return0;}3.父进程从终端读取要执行的命令,并交给子进程执行。父进程等待子进程结束,并打印子进程的返回值。
提示:从终端读取要执行的命令可用fgets()实现。#include<stdlib.h>#include<string.h>#include<unistd.h>#include<sys/types.h>#include<sys/wait.h>#include<stdio.h>charcommand[256];intmain(){intrtn,errorno;while(1){printf(">");fgets(command,256,stdin);command[strlen(command)-1]=0;printf("command=%s\n",command);if(fork()==0){errorno=execlp(command,command,NULL,NULL);perror(command);exit(errorno);}else{wait(&rtn);
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 【正版授权】 IEC 60601-2-46:2023 CMV EN Medical electrical equipment - Part 2-46: Particular requirements for the basic safety and essential performance of operating tables
- 【正版授权】 IEC 60601-2-37:2001+AMD1:2004 CSV EN Medical electrical equipment - Part 2-37: Particular requirements for the safety of ultrasonic medical diagnostic and monitoring equipment
- 【正版授权】 IEC 60546-2:2010 EN-FR Controllers with analogue signals for use in industrial-process control systems - Part 2: Guidance for inspection and routine testing
- 【正版授权】 IEC 60534-1:2023 EN-FR Industrial-process control valves - Part 1: Control valve terminology and general considerations
- 【正版授权】 IEC 60519-1:2020 EN-FR Safety in installations for electroheating and electromagnetic processing - Part 1: General requirements
- 【正版授权】 IEC 60512-7-1:2010 EN-FR Connectors for electronic equipment - Tests and measurements - Part 7-1: Impact tests (free connectors) - Test 7a: Free fall (repeated)
- 【正版授权】 IEC 60512-20-1:2010 EN-FR Connectors for electronic equipment - Tests and measurements - Part 20-1: Fire hazard tests - Test 20a: Flammability,needle-flame
- 【正版授权】 IEC 60512-12-4:2006 EN-FR Connectors for electronic equipment - Tests and measurements - Part 12-4: Soldering tests - Test 12d: Resistance to soldering heat,solder bath method
- 【正版授权】 IEC 60510-2-1:1978 EN-FR Methods of measurement for radio equipment used in satellite earth stations. Part 2: Measurements for sub-systems. Section One: General - Section Two: Antenna
- 【正版授权】 IEC 60487-3-2:1981 EN-FR Methods of measurement for equipment used in terrestrial radio-relay systems - Part 3: Simulated systems - Section Two: Measurements in the baseband
- 2023中国煎炸菜品趋势报告 -大数据赋能餐企持久创新力
- 2024-2029年中国水貂皮行业市场现状分析及竞争格局与投资发展研究报告
- 数据标注项目策划书
- JTGT J21-01-2015 公路桥梁荷载试验规程
- GB/T 43633-2024法庭科学DNA实验室建设规范
- 琴行音乐会活动方案
- 《运动治疗技术》课程标准
- 2023年12月英语六级真题及参考答案
- 2024年安徽淮北建投控股集团有限公司招聘笔试参考题库含答案解析
- 天地科技上海采掘机械设备-采煤机
- 承插式盘扣外架在圆弧形结构的运用与分析
评论
0/150
提交评论