/MY PROGRAM ARE COMPILED IN FEDORA15 ..WITH 4.6 gcc compiler...../
/* writer1 */
#include<stdio.h>
#include<stdlib.h>
#include<fcntl.h>
#include<sys/ipc.h>
#include<unistd.h>
#include<sys/types.h>
#include"header.h"
//int sem=1;
//extern int sem;
int main()
{
int ret,wfd,count=0;
int buff=5;
int a=10;
int b=15;
ret=mkfifo("anu",777|IPC_CREAT);
if(ret==0)
printf("fifo created\n");
if(sem==1)
{
sem=0;
wfd=open("anu",O_WRONLY);//after opening ...if it finds a reader...it will write data to fifo untill its limit exceeds ...when limit came...it will allow reader to read ...then again starts wriiting to fifo..
printf("wfd=%d\n",wfd);
count=write(wfd,&buff,4);
printf("count=%d buff=%d\n",count,buff);
//fd=open("anu",O_WRONLY);
//printf("fd=%d\n",fd);
close(wfd);
wfd=open("anu",O_WRONLY);//same reader will works for no. of writers
printf("wfd=%d\n",wfd);
count=write(wfd,&a,4);
printf("count=%d a=%d\n",count,a);
close(wfd);//it will make no diffrence if i opened same fifo after closing....data will remain in that fifo......
wfd=open("anu",O_WRONLY);
printf("wfd=%d\n",wfd);
count=write(wfd,&b,4);
printf("count=%d b=%d\n",count,b);
close(wfd);
//sleep(1);
}
sem=1;
return 0;//once all writers process is terminated..so no writer is there ...means reader will not be able to reader..data from fifo will be erased ....& then again it opens demands a reader to read to come out of block on open position
wfd=open("anu",O_WRONLY);//after opening ...if it finds a reader...it will write data to fifo untill its limit exceeds ...when limit came...it will allow reader to read ...then again starts wriiting to fifo..
printf("wfd=%d\n",wfd);
count=write(wfd,&buff,4);
printf("count=%d\nbuff=%d\n",count,buff);
//fd=open("anu",O_WRONLY);
//printf("fd=%d\n",fd);
close(wfd);
wfd=open("anu",O_WRONLY);//same reader will works for no. of writers
printf("wfd=%d\n",wfd);
count=write(wfd,&a,4);
printf("count=%d\na=%d\n",count,a);
close(wfd);//it will make no diffrence if i opened same fifo after closing....data will remain in that fifo......
wfd=open("anu",O_WRONLY); printf("wfd=%d\n",wfd);
count=write(wfd,&b,4);
printf("count=%d\nb=%d\n",count,b);
close(wfd);
//sleep(1);
}
sem=1;
return 0;//once writer process is terminated & means reader will not be able to read...data from fifo will be erased ....& then again it opens demands a reader to read to come out of block on open position
wfd=open("anu",O_WRONLY);//after opening ...if it finds a reader...it will write data to fifo untill its limit exceeds ...when limit came...it will allow reader to read ...then again starts wriiting to fifo..
printf("wfd=%d\n",wfd);
count=write(wfd,&buff,4);
printf("count=%d\nbuff=%d\n",count,buff);
//fd=open("anu",O_WRONLY);
//printf("fd=%d\n",fd);
close(wfd);
wfd=open("anu",O_WRONLY);//same reader will works for no. of writers
printf("wfd=%d\n",wfd);
count=write(wfd,&a,4);
printf("count=%d\na=%d\n",count,a);
close(wfd);//it will make no diffrence if i opened same fifo after closing....data will remain in that fifo......
wfd=open("anu",O_WRONLY);
printf("wfd=%d\n",wfd);
count=write(wfd,&b,4);
printf("count=%d\nb=%d\n",count,b);
close(wfd); //sleep(1);
sem=1;
}
return 0;//once writer process is terminated & means reader will not be able to read...data from fifo will be erased ....& then again it opens demands a reader to read to come out of block on open position
int main() { //sleep(2); int ret,i=0,fd; int count,buf,a,b; ret=mkfifo("anu",777|IPC_CREAT); if(ret==0) printf("fifo created\n"); for(i=1;i<4;i++) { printf("**********i=%d**********\n",i); fd=open("anu",O_RDONLY);//when both writer & reader r executing ...untill then ...reader can read the written data......otherwise again operating same reader will demand new writer ...that shold open now..& start wriiting data freshly... printf("fd=%d\n",fd); read(fd,&buf,4);//reader is able to read only upto the time in millisecond...untill there is writer..& no writting program or process is finished.....if i had made delay of 1 sec at staring of the this reader....untill then writer completes its work..& finished...no wait by writer untill fifo is full...then after that data will not be read....writer should be there if u want to read data from fifo.... printf("buf=%d\n",buf); printf("buf=%d\n",buf);