- 论坛徽章:
- 0
|
1 #include<sys/types.h>
2 #include<sys/stat.h>
3 #include<string.h>
4 #include<stdio.h>
5 #include<fcntl.h>
6 #include<time.h>
7 #define FIFO "/tmp/fifo"
8 int main()
9 {
10 char buffer[80];
11 int fd;
12 int n;
13 int m;
14 const time_t t;
15 int ret;
16 char info[80];
17 unlink(FIFO);
18 ret=mkfifo(FIFO,0600);
19 if(ret)
20 {
21 error("mkfifo error");
22 return -1;
23 }
24 memset(info,0x00,sizeof(info));
25 //strcpy(info,"i m nieshizhong!");
26 sleep(10);
27 fwirte(info,"I'm nieshizhong %s\n",asctime(localtime(&t)) );
28 fd=open(FIFO,O_WRONLY);
29 n=write(fd,info,strlen(info));
30 if(n<0)
31 {
32 perror("write error");
33 return -1;
34 }
35
36 m=read(fd,buffer,80);
37 if(m<0)
38 {
39 perror("read error!");
40 return -1;
41 }
42 sleep(5);
43 printf("%S\n",buffer);
44
45 close(fd);
46 return 0;
-- 插入 -- 14,5 顶端
|
|