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
| #include <stdio.h> #include <string.h> #include <fcntl.h> #include <sys/stat.h> int main(int argc, char **argv) { int sfd,dfd,sp,dp,iofile; char buff[1024]; sfd=open("in.txt",O_RDONLY,0644); dfd=open("out.txt",O_WRONLY|O_CREAT|O_TRUNC,0644); mknod("iofile",S_IFIFO|0666,0); if(fork()) { sp=open("iofile",O_WRONLY); while((n=read(sfd,buff,1024))>0) write(pp,buff,n); close(sp); close(sfd); } else { dp=open("iofile",O_RDONLY|O_NDELAY); while((n= read(dp,buff,1024))!=1) if(n==0) sleep(5); else write(df,buff,strlen(buff)); close(dp); close(dfd); } return 0; }
|