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.
Asked
Active
Viewed 2,092 times
0
-
I've never heard of a shell command that does this. – Barmar Nov 27 '14 at 02:32
-
If you don't want to use Python, how about Perl? – Barmar Nov 27 '14 at 02:33
-
I am fine if there's any C language solution. The program should read whatever currently inside `trace_pipe` is and returns. If it is empty, it should immediately quite. – Javad Nov 27 '14 at 03:48
1 Answers
1
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.

user3426575
- 1,723
- 12
- 18
-
This is indeed a solution, however, I would like to sample `trace_pipe` every second. Your approach increases the system load which is undesirable for my use case. – Javad Nov 27 '14 at 03:46
-
It's the same as with `cat`: if you want the command to run in the background, add an `&` at the end of the invocation. This shouldn't increase the system load any more than running it the normal way does. – user3426575 Nov 27 '14 at 21:46