Chinaunix首页 | 论坛 | 博客
  • 博客访问: 108273
  • 博文数量: 74
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 757
  • 用 户 组: 普通用户
  • 注册时间: 2013-10-20 22:42
个人简介

相信生命中的无限潜能

文章分类

全部博文(74)

文章存档

2016年(1)

2015年(30)

2014年(30)

2013年(13)

我的朋友

分类: C/C++

2014-02-20 16:29:17


  1. #include <stdio.h>
  1. #include <sys/types.h>
  1. #include <sys/stat.h>
  1. #include <fcntl.h>
  1. #include <unistd.h>
  1. #include <signal.h>
  1. #include <stdlib.h>
  1. int i=0;
  1. int *p;
  1. int fd;
  1. void over()
  1. { /*关闭管道文件*/
  1.     close(fd);
  1.     /*删除管道文件*/
  1.     unlink("pipe.txt");
  1.     exit(-1);
  1. }
  1. int main()
  1. {
  1.     signal(SIGINT,over);
  1.     /*建立管道*/
  1.     mkfifo("pipe.txt",0666);
  1.     /*打开管道*/
  1.     fd = open("pipe.txt",O_RDWR);
  1.     while(1)
  1.     {
  1.         sleep(1);
  1.         write(fd,&i,4);
  1.         i++;
  1.     }
  1.     return 0;
  1. }



  1. #include <stdio.h>
  1. #include <fcntl.h>
  1. #include <sys/mman.h>
  1. #include <signal.h>
  1. #include <stdlib.h>
  1. int fd;
  1. void over()
  1. {
  1.     close(fd);
  1.     exit(-1);
  1. }
  1. int main()
  1. {
  1.     signal(SIGINT,over);
  1.     int i=0;
  1.     fd=open("pipe.txt",O_RDWR);
  1.     while(1)
  1.     {
  1.         read(fd,&i,4);
  1.         printf("%d\n",i);
  1.     }
  1. }


阅读(702) | 评论(0) | 转发(0) |
0

上一篇:pause_signal

下一篇:pipe

给主人留下些什么吧!~~