PIPE IMPLEMENTATION IN C | LINUX IPC IMPLEMENTATION IN C | C PROGRAM TO IMPLEMENT IPC EVENT
Pipe(Inter process Communication Event) Implementation in C Language :
1 |
#include"headers.h"<br />main()<br />{<br /> int p[2];int size,st;<br /> char buf[1000];<br /> bzero(buf,1000);<br /> pipe(p);<br /> printf("%d and %d are created by pipe..n",p[0],p[1]);<br /> int chldpid;<br /><br /> if((chldpid = fork()))<br /> {//client... parent...<br /> char file[20];<br /> printf("Enter File Name ..:");<br /> scanf("%s",file);<br /> size = strlen(file);<br /> write(p[1],&size,4);<br /> write(p[1],file,size);<br /> wait(&st);<br /> read(p[0],&size,4);<br /> read(p[0],buf,size);<br /> write(1,buf,size);<br /> }<br /> else<br /> {//child ... server ...<br /> int s,fd;<br /> int s2;<br /> read(p[0],&s,4);<br /> printf("Size in child ..%d n",s);<br /> char fname[20],*buff;<br /> bzero(fname,20);<br /> read(p[0],fname,s);<br /> printf("In child file name :%s..n",fname);<br /> fd=open(fname,O_RDONLY);<br /> if(fd &lt 0)<br /> {<br /> s2 = 26;<br /> write(1,"open failed..n",15);<br /> write(p[1],&s2,4);<br /> write(p[1],"Error File Doesn't Exist..",26);<br /> }<br /> else<br /> {<br /> s2 = lseek(fd,0,SEEK_END);<br /> buff =(char *) malloc(s2+1);<br /> lseek(fd,0,SEEK_SET);<br /> read(fd,buff,s2);<br /> close(fd);<br /> write(p[1],&s2,4);<br /> write(p[1],buff,s2);<br /> }<br /> exit(0);<br /> }<br /><br />}<br /> |