1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
#include <stdio.h>
int main()
{
setvbuf(stdout,NULL,_IONBF,0);
/*
FILE *f=fopen("~testpipe","rw");
int pid=_fork();
if(pid==0)
{
char buf[2];
fread(buf,1,1,f);
printf("[%c]\n",buf[0]);
while(1);
}
else
{
char buf[]="666";
fwrite(buf,1,1,f);
printf("written\n");
while(1);
}
*/
int f=_open("~testpipe","RW");
int pid=_fork();
if(pid==0)
{
char buf[2];
while(_read(f,buf,1))printf("%c",buf[0]);
}
else
{
char buf[]="666 the number of the beast";
_write(f,buf,27);
printf("written\n");
}
}
|