How to flush a pipe using bash

后端 未结 3 2202
别跟我提以往
别跟我提以往 2021-01-02 01:44

I have a script that writes to a named pipe and another that reads from the pipe. Occasionally, when starting the script I have noticed that the contents of the pipe exist

3条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-02 02:35

    I think dd is your friend:

    dd if=myfifo iflag=nonblock of=/dev/null
    

    strace shows

    open("myfifo", O_RDONLY|O_NONBLOCK)
    

    and indeed doesn't even block on an empty fifo.

提交回复
热议问题