When creating a FIFO pipeline, open will block?
Or is there a problem with my code?
- #include <stdio.h>
- #include <unistd.h>
- #include <fcntl.h>
- #include <errno.h>
- #include <sys/types.h>
- #Include <sys/stat.h>
- #define FIFO1 "/tmp/fifo.1"
- #define FIFO2 "/tmp/fifo.2"
- #define File_mode (S_IRUSR | S_IWUSR | S_irgrp | S_iroth)
- int main ()
- {
- int RfD, WFD;
- if ((Mkfifo (FIFO1, File_mode) < 0) && errno! = eexist)
- {//error
- Exit (0);
- }
- if ((Mkfifo (FIFO2, File_mode) < 0) && errno! = eexist)
- {//error
- Exit (0);
- }
- fprintf (stderr, "before open\n");
- RFD = open (FIFO1, o_rdonly, 0);
- WFD = open (FIFO2, o_wronly, 0);
- fprintf (stderr, "after open\n");
- There is a problem here and after Open has not been printed.
- }
Man 3 Open. The interpretation of General 3 is more detailed than the explanation of 2.
- O_nonblock
- When opening a FIFO with O_rdonly or o_wronly set:
- * If O_nonblock is set, a open () for reading-only shall return without delay. An open () for writing-only shall return an error if no process currently have the file open for reading.
- * If O_nonblock is clear, an open () for reading-only shall block the calling thread until a thread opens the file for Writing. An open () for writing-only shall block, the calling thread until a thread opens the file for reading.
Copy Code
UNIX Network Programming Volume 2 43rd Page pipeline: Open unexpectedly blocked?