/* * fifoRead.c++ shows that the process is blocked on open * as there is no writing process * $ mkfifo -m 0666 myFIFO * $ g++ -Wall fifoRead.c++ -o fifoRead * $ g++ -Wall fifoWrite.c++ -o fifoWrite * $ ./fifoRead myFIFO & * $ ./fifoWrite myFIFO & */ #include using namespace std; #include #include #include #include #include #include #include #define MAX 100 // $ mkfifo -m 0666 myFIFO // $ g++ -Wall fifoRead.c++ -o fifoRead // $ g++ -Wall fifoWrite.c++ -o fifoWrite // $ ./fifoRead myFIFO & // $ ./fifoWrite myFIFO & int main(int ac, char *av[]) { int pd; char buff[MAX]; if(ac < 2){ cerr << "FIFO name not specified\n"; exit(1); } pd = open(av[1], O_RDONLY); if(pd == -1){ cerr << "FIFO open error\n"; exit(1); } cout << "Not printed until fifoWrite\n"; read(pd, buff, 100); cout << "Data read: " << buff << endl; close(pd); return 0; }