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