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(4);
return 0;//once all writers process is terminated..so no writer is there ...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);
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);
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
//Every new process reader is for new process writer ......it does not matters either i m opening fifo..... again & again after closing wfd....in one process ...to read data by executing another program no. of times....means every time new reader of process will demand a new writer of process ..
#include<stdio.h>
#include<stdlib.h>
#include<fcntl.h>
#include<unistd.h>
int main()
{
//sleep(2);
int i=0,fd;
int count,buf,a,b;
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....
//Every new process reader is for new process writer ......it does not matters either i m opening fifo..... again & again after closing wfd....in one process ...to read data by executing another program no. of times....means every time new reader of process will demand a new writer of process ..
#include<stdio.h>
#include<stdlib.h>
#include<fcntl.h>
#include<unistd.h>
int main()
{
//sleep(1);
int fd;
int count,buf,a,b;
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);
count=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....
//Every new process reader is for new process writer ......it does not matters either i m opening fifo..... again & again after closing wfd....in one process ...to read data by executing another program no. of times....means every time new reader of process will demand a new writer of process ..
#include<stdio.h>
#include<stdlib.h>
#include<fcntl.h>
#include<unistd.h>
int main()
{
sleep(1);
int fd;
int count,buf,a,b;
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....
If three writers r writting at the same instance of time...i.e. by using..... ./1st writer & ./2nd writer & ./3rd writer ..........& on other side all readers r operated ,,,,,,, ./1st reader & ./2nd reader & ./3rd reader.......
then.........3 writer will take time of one writer .........so only any of one reader may read at the same time of writing three readers........
*If i have two writers & two readers at the same time .....two readers r waiting to read..& i have operated two writers....writer operated 1st will be read by both of the readers..half-half...another writer which has operated late now require a new reader
*If i have 2 writers & 2 readers & readers r waiting for writers to write....if i have executed writer programs.....in background process like using command <writer1.c & writer2.c> <>will not be used in command......so background process will also take time of nenosecond to make in that time .....signals by kernel SIGPIPE goes to both readers one by one ...reader who got signal 1st will start reading..& who got signal 2nd will in 1 nenosecond will execute 2nd writer that will run in background process ...
*If by chance 2nd reader got signal before background process made ...then at that instant of time...reader will read garbage from fifo.....but writer will still wait for reader..which has already read garbage......time is managed internally...but problem will come it i had used sleep in read process...will make delay to read...so not able to read properly...untill writing got finished...
*Writer after writing will never wait for reader to read.......imagine if it will happen....how nice fifo would be.....?