资源简介
ziyuanbao
代码片段和文件信息
#include
#include
#include
int main(int argc char **argv)
{
int pidfd1fd2;
sem_id sem1sem2;
sem1=create_sem(1“piperun“);
sem2=create_sem(1“piperun“);
if (sem1 perror(“create_sem“);
exit(1);
}
acquire_sem(sem1);
acquire_sem(sem2);
pid=fork();
if (pid==0) {
fd1=open(“/pipe/1“O_WRONLY|O_CREAT0666);
if (fd1==-1) {
perror(“writer: /pipe/1“);
_exit(1);
}
release_sem(sem1);
/* wait for other side to open the pipe 1 */
acquire_sem(sem2);
/* wait for creation of pipe 2 */
acquire_sem(sem1);
fd2=open(“/pipe/2“O_RDONLY);
if (fd2==-1) {
perror(“/pipe/2“);
_exit(1);
}
release_sem(sem2);
dup2(fd20);
dup2(fd11);
system(argv[2]);
_exit(1);
}
acquire_sem(sem1);
fd1=open(“/pipe/1“O_RDONLY);
release_sem(sem2);
if (fd1==-1) {
perror(“/pipe/1“);
exit(1);
}
fd2=open(“/pipe/2“O_WRONLY|O_CREAT0666);
if (fd2==-1) {
perror(“writer: /pipe/2“);
exit(1);
}
release_sem(sem1);
/* wait for child to open ... */
acquire_sem(sem2);
dup2(fd10);
dup2(fd21);
system(argv[1]);
exit(0);
}
- 上一篇:随机减量方法
- 下一篇:电子科技大学分布式系统研究生期末考试
评论
共有 条评论