#include #include #include #define maxsize 1000 //ipc-pipe-2.c char buffer [maxsize]; void server(int readfd){ while (read(readfd,buffer,sizeof(buffer)) > 0) printf("%s",buffer); printf("\n"); } void client(int writefd){ FILE * fp; char line[1000]; fp=fopen("/home/mumolo/testsmall.txt","r"); while(fgets(line,sizeof(line),fp)!=NULL) write(writefd,line,sizeof(line)); } int main(){ int pfd[2], pid, status; pipe(pfd); pid=fork(); if(pid>0) { close(pfd[1]); server(pfd[0]); wait(&status); exit(0); } else { close(pfd[0]); sleep(1); /* il client aspetta mentre il server legge la pipe */ client(pfd[1]); exit(0); } }