Linux non-blocking fifo (on demand logging)

前端 未结 10 2326
你的背包
你的背包 2020-11-29 19:20

I like to log a programs output \'on demand\'. Eg. the output is logged to the terminal, but another process can hook on the current output at any time.

The classic

10条回答
  •  难免孤独
    2020-11-29 20:09

    It seems like bash <> redirection operator (3.6.10 Opening File Descriptors for Reading and WritingSee) makes writing to file/fifo opened with it non-blocking. This should work:

    $ mkfifo /tmp/mylog
    $ exec 4<>/tmp/mylog
    $ myprogram 2>&1 | tee >&4
    $ cat /tmp/mylog # on demend
    

    Solution given by gniourf_gniourf on #bash IRC channel.

提交回复
热议问题