Wednesday, June 27, 2012


// program on FIFO

 # include <stdio.h>
 # include <sys/types.h>
 # include <sys/stat.h>
 # include <fcntl.h>
 int main()
 {
 int fd;
 char buff[100];
 /*creating FIFO */
 if((mkfifo("./MyFifo",S_IFIFO|S_IRWXU|S_IRWXG|S_IRWXO))<0)
 perror("\nmkfifo error...");

 /*creating reader process...*/

 fd=open("./MyFifo",O_RDONLY|O_NONBLOCK);
 while(read(fd,buff,sizeof(buff))>0)
 printf("%s",buff);
 /*creating write process */

 fd=open("./MyFifo",O_WRONLY);
 write(fd,"Hello world",12);
 close(fd); 
 }

No comments:

Post a Comment