资源简介
四次实验,进程控制,线程同步与通信,共享内存与进程同步,linux
文件目录

代码片段和文件信息
#include
#include
#include
#include
#include
#define t 10
int my_pipe[2];
pid_t pid_1pid_2;
void killprocess(int sign){
printf(“\n“);
if(sign == SIGINT){ //传递SIGUSR信号给子进程
kill(pid_1SIGUSR1);
kill(pid_2SIGUSR1);
}
}
void killpid1(){
close(my_pipe[0]);
if(pid_1== 0 ){
printf(“Child Process1 is killed by Parent!\n“);
exit(0);
}
}
void killpid2(){
close(my_pipe[1]);
if(pid_2 == 0 ){
printf(“Child Process2 is killed by Parent!\n“);
exit(0);
}
}
int main(void){
int x=1;
char buffer1[100];
char buffer2[100];
if(pipe(my_pipe)<0){
printf(“ERROR“);
return -1;
}
//设置软中断信号SIGINT
signal(SIGINTkillprocess);
//创建子进程cls
pid_1=fork();
if(pid_1==0){
signal(SIGINTSIG_IGN);
signal(SIGUSR1killpid1);
alarm(t);
signal(SIGALRMkillpid1);
while(1){
sprintf(buffer1“I send you %d times“x);
write(my_pipe[1]buffer130);
x++;
sleep(1);
}
}
pid_2=fork();
if(pid_2==0){
signal(SIGINTSIG_IGN);
signal(SIGUSR1killpid2);
alarm(t);
signal(SIGALRMkillpid2);
while(1){
read(my_pipe[0]buffer240);
printf(“%s\n“buffer2);
}
}
// else{
waitpid(pid_1NULL0);//等待子进程退出
waitpid(pid_2NULL0);
close(my_pipe[0]);//关闭管道
close(my_pipe[1]);
printf(“Parent Process is killed!\n“);
// }
return 0;
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 1682 2019-01-09 05:36 1.c
文件 1313 2018-12-17 00:33 2.c
文件 559 2018-12-17 00:33 2.h
文件 928 2018-12-24 01:18 3.c
文件 1028 2018-12-24 01:04 3.h
文件 2446 2018-12-28 18:39 4.c
----------- --------- ---------- ----- ----
7956 6
- 上一篇:华中科技大学汇编实验
- 下一篇:山东大学操作系统2017-2018复习提纲
相关资源
- cocos2D 超级马里奥
- 操作系统哲学家就餐问题(界面+源码
- Effect of Erosion and Sedimentation on Storage
- Predicting the Deposited Sediment Volume Case
- Electric potential drops across a crack gap in
- boost::asio::serial下6个工程演示多种串口
- 可以在XE下使用的DosCommand,捕获控制
- 解决检索 COM 类工厂中 CLSID 为 {96749
- FreeRTOS采样ADC+KEY事件信号+DMA串口收发
- Microservices_Designing_Deploying
- 原创:AnyExe2Swf flash exe文件还原、反
- DOS中断和BIOS中断手册
- 电脑BIOS设置各种中英文对照表
- CiscoWorks QoS Policy Manager白皮书英文
- The IDA Pro Book 2nd Edition
- nmos转移特性曲线hspice程序—&mdas
- Beginning STM32: Developing with FreeRTOS libo
- Chameleon_2.3svn_r2466_trunk_pkg+wowpc;os x 10
- PalmOS一些常识
- Palm OS应用程序设计指南
- Palm OS基础入门
- 技嘉H310M S2 BIOS
- jboss5.1地址
- msdos7.1完整版
- MS-DOS6.22简体中文版安装镜像
- Win98Dos启动盘的盘镜像纯净版
- DOS98.IMG启动文件
- Dos6.22光盘启动iso
- 技嘉z77p-d3 rev 1.0 添加nvme模块的最新
- IOS水印
评论
共有 条评论