Nonblocking read from a pipe in Linux

2.2k views Asked by At

I would like to read /sys/kernel/debug/tracing/trace_pipe in non-blocking way using Linux command-line tools. For instance, cat cannot be used, because it will be blocked. This is similar to this, with the difference that I don't want to use Python.

1

There are 1 answers

2
user3426575 On

The concept of ‘non-blocking’ doesn't apply to command-line tools. However, you could run an instance of cat in the background by appending an ampersand to the invocation, like so:

cat /sys/kernel/debug/tracing/trace_pipe &

Now, the command returns immediately, and every time a line is readable from the file, it gets printed to the terminal (and messes up whatever you were typing).

You could also use tail -F if the file itself doesn't block.