UNIX Network Programming Volume 2 43rd Page pipeline: Open unexpectedly blocked?

Source: Internet
Author: User

When creating a FIFO pipeline, open will block?
Or is there a problem with my code?

  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <fcntl.h>
  4. #include <errno.h>
  5. #include <sys/types.h>
  6. #Include <sys/stat.h>
  7. #define FIFO1 "/tmp/fifo.1"
  8. #define FIFO2 "/tmp/fifo.2"
  9. #define File_mode (S_IRUSR | S_IWUSR | S_irgrp | S_iroth)
  10. int main ()
  11. {
  12. int RfD, WFD;
  13. if ((Mkfifo (FIFO1, File_mode) < 0) && errno! = eexist)
  14. {//error
  15. Exit (0);
  16. }
  17. if ((Mkfifo (FIFO2, File_mode) < 0) && errno! = eexist)
  18. {//error
  19. Exit (0);
  20. }
  21. fprintf (stderr, "before open\n");
  22. RFD = open (FIFO1, o_rdonly, 0);
  23. WFD = open (FIFO2, o_wronly, 0);
  24. fprintf (stderr, "after open\n");
  25. There is a problem here and after Open has not been printed.
  26. }

Man 3 Open. The interpretation of General 3 is more detailed than the explanation of 2.

    1. O_nonblock
    2. When opening a FIFO with O_rdonly or o_wronly set:
    3. * 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.
    4. * 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?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.