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