Why does a read-only open of a named pipe block?

后端 未结 1 1905
时光说笑
时光说笑 2020-12-02 09:52

I\'ve noticed a couple of oddities when dealing with named pipes (FIFOs) under various flavors of UNIX (Linux, FreeBSD and MacOS X) using Python. The first, and perhaps mos

相关标签:
1条回答
  • 2020-12-02 10:33

    That's just the way it's defined. From the Open Group page for the open() function

    O_NONBLOCK
    
        When opening a FIFO with O_RDONLY or O_WRONLY set: If O_NONBLOCK is
        set:
    
            An open() for reading only will return without delay. An open()
            for writing only will return an error if no process currently
            has the file open for reading.
    
        If O_NONBLOCK is clear:
    
            An open() for reading only will block the calling thread until a
            thread opens the file for writing. An open() for writing only
            will block the calling thread until a thread opens the file for
            reading.
    
    0 讨论(0)
提交回复
热议问题