操作系统实验一、进程间的通信(共5页).docx

上传人:飞****2 文档编号:16294728 上传时间:2022-05-16 格式:DOCX 页数:5 大小:12.32KB
返回 下载 相关 举报
操作系统实验一、进程间的通信(共5页).docx_第1页
第1页 / 共5页
操作系统实验一、进程间的通信(共5页).docx_第2页
第2页 / 共5页
点击查看更多>>
资源描述

《操作系统实验一、进程间的通信(共5页).docx》由会员分享,可在线阅读,更多相关《操作系统实验一、进程间的通信(共5页).docx(5页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

1、精选优质文档-倾情为你奉上#include#include#include#include#include #include int i,wait_mark;void waiting(),stop();void shiyan1_part1()int p1,p2;while(p1=fork()=-1);if(p1=0)printf(bn);elsewhile(p2=fork()=-1);if(p2=0)printf(cn);elseprintf(an);void shiyan1_part2_1()int p1,p2;while(p1=fork()=-1);if(p1=0)for(i=0;i10;

2、i+)printf(我是子进程1n);elsewhile(p2=fork()=-1);if(p2=0)for(i=0;i10;i+)printf(我是子进程2n);elsefor(i=0;i10;i+)printf(我是父进程n);void shiyan1_part2_2()int p1,p2;while(p1=fork()=-1);if(p1=0)lockf(1,1,0);for(i=0;i10;i+)printf(我是子进程1n);lockf(1,0,0);elsewhile(p2=fork()=-1);if(p2=0)lockf(1,1,0);for(i=0;i10;i+)printf(

3、我是子进程2n);lockf(1,0,0);elselockf(1,1,0);for(i=0;i0) while(p2=fork()=-1); if(p20) printf(this is parent processn); wait_mark=1; signal(SIGINT,stop); waiting(); kill(p1,1); kill(p2,2); wait(0); wait(0); printf(nparent process is killedn); exit(0); else printf(this is child process p2n); signal(SIGINT,s

4、top); /signal(SIGQUIT,SIG-IGN); wait_mark=1; signal(2,stop); waiting(); lockf(1,1,0); printf(nchild process p2 is killed by parentn); lockf(1,0,0); exit(0); else printf(this is child process p1n); signal(SIGINT,stop); /signal(SIGQUIT,SIG-IGN); wait_mark=1; signal(1,stop); waiting(); lockf(1,1,0); pr

5、intf(nchild process p1 is killed by parent!n); lockf(1,0,0); exit(0); void shiyan1_part3_2() int p1,p2; while(p1=fork()=-1); if(p10) while(p2=fork()=-1); if(p20) printf(this is parent processn); wait_mark=1; signal(SIGINT,stop); waiting(); kill(p1,1); kill(p2,2); wait(0); wait(0); printf(nparent pro

6、cess is killedn); exit(0); else printf(this is child process p2n); signal(SIGINT,SIG_IGN); /signal(SIGQUIT,SIG_IGN); wait_mark=1; signal(2,stop); waiting(); lockf(1,1,0); printf(nchild process p2 is killed by parentn); lockf(1,0,0); exit(0); else printf(this is child process p1n); signal(SIGINT,SIG_

7、IGN); /signal(SIGQUIT,SIG_IGN); wait_mark=1; signal(1,stop); waiting(); lockf(1,1,0); printf(nchild process p1 is killed by parent!n); lockf(1,0,0); exit(0); void shiyan1_part4() int pid1,pid2; int fd3; char OutPipe100,InPipe100; pipe(fd); while(pid1=fork()=-1); if(pid1=0) printf(Subprocess p1 is go

8、ing to send msg!n); lockf(fd1,1,0); sprintf(OutPipe,Subprocess p1 sent msg!n); write(fd1,OutPipe,50); sleep(5); lockf(fd1,0,0); exit(0); else while(pid2=fork()=-1); if(pid2=0) sleep(5); printf(Subprocess p2 is going to send msg!n); lockf(fd1,1,0); sprintf(OutPipe,Subprocess p2 sent msg!n); write(fd1

9、,OutPipe,50); sleep(1); lockf(fd1,0,0); exit(0); else printf(parentn); wait(0); read(fd0,InPipe,50); printf(%sn,InPipe); wait(0); read(fd0,InPipe,50); printf(%sn,InPipe); exit(0); int main()/shiyan1_part1();/shiyan1_part2_1();/shiyan1_part2_2();/shiyan1_part3_1();/shiyan1_part3_2(); /shiyan1_part4();return 0;void waiting() while(wait_mark!=0);void stop() wait_mark=0;专心-专注-专业

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 教案示例

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁