#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/sem.h>
#include <sys/wait.h>
#include <string.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include "2.h"
union semun {
int val; /* Value for SETVAL */
struct semid_ds *buf; /* Buffer for IPC_STAT, IPC_SET */
unsigned short *array; /* Array for GETALL, SETALL */
struct seminfo *__buf; /* Buffer for IPC_INFO*/
} arg;
void main(){
semid = semget(100,4,IPC_CREAT|0666);
arg.val = 1;
semctl(semid,0,SETVAL,arg);
arg.val = 0;
semctl(semid,1,SETVAL,arg);
arg.val = 1;
semctl(semid,2,SETVAL,arg);
arg.val = 0;
semctl(semid,3,SETVAL,arg);//初始化信号量集
shmid_S = shmget(200,sizeof(char)*BUFSIZE,IPC_CREAT|0666);
shmid_T = shmget(201,sizeof(char)*BUFSIZE,IPC_CREAT|0666);
shmid_copy_stop = shmget(202,sizeof(char)*BUFSIZE,IPC_CREAT|0666);
shmid_put_stop = shmget(203,sizeof(char)*BUFSIZE,IPC_CREAT|0666);
data_of_S = shmat(shmid_S,NULL,0);
memset(data_of_S,'\0',BUFSIZE);
data_of_T = shmat(shmid_S,NULL,0);
memset(data_of_T,'\0',BUFSIZE);
data_of_copy_stop = shmat(shmid_S,NULL,0);
*data_of_copy_stop = 0;
data_of_put_stop = shmat(shmid_S,NULL,0);
*data_of_put_stop = 0;
if(0 == (pid1=fork())){
puts("get process is running");
execl("./get","get",NULL);
}
else if(0 == (pid2=fork())){
puts("copy process is running");
execl("./copy","copy",NULL);
}
else if(0 == (pid3=fork())){
puts("put process is running");
execl("./put","put",NULL);
}
else{
waitpid(pid1,NULL,0);
waitpid(pid2,NULL,0);
waitpid(pid3,NULL,0);
semctl(semid,0,IPC_RMID);
shmdt(data_of_copy_stop);
shmdt(data_of_put_stop);
shmctl(shmid_S,IPC_RMID,NULL);
shmctl(shmid_T,IPC_RMID,NULL);
shmctl(shmid_copy_stop,IPC_RMID,NULL);
shmctl(shmid_put_stop,IPC_RMID,NULL);
}
}
inux-C--.rar_誊抄
版权申诉
190 浏览量
2022-09-23
17:28:54
上传
评论
收藏 16KB RAR 举报
weixin_42653672
- 粉丝: 93
- 资源: 1万+
最新资源
- 笔记实验六,spark,大数据分析
- ####蓝桥杯python的详细的信息介绍
- 电子万年历软件仿真(经过多次修改,保证正确性)
- Unity XR 手势射击控制脚本(适用于任何可手势识别的设备)
- 机械设计全自动电表(NB和IC卡表)控制和上壳装配线sw16可编辑非常好的设计图纸100%好用.zip
- 基于matlab的EAN-13条形码识别系统GUI界面.zip代码53
- matlab基于bp神经网络交通信号标志识别GUI界面13个标志.zip代码54
- 电子万年历答辩实物展示视频mp4格式
- 基于python实现的程序,包括哈希感知算法cvHash,图像切割cvsplit,固定目标检测cvRec(附文档ppt)等
- 计算0-10000之间所有偶数的和
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈