I'm trying to solve a simple problem.
I wish to start a long-running program in verbose mode, but I want to trash all of its output by default, and when some misbehavior occurs I wish to reattach the output to my terminal.
The program itself is started by a systemctl rule.
I thought on various solutions:
- Starting it as
program > /dev/null
and use someptrace
later to change the default output when investigation is needed - Starting it as
mkfifo /tmp/mystdout; program > /tmp/mystdout
and later cat the contents of the fifo
However I want to detect which approach is more effective, taking into account that 95% of the output is not needed to keep. (I know outputting to fifo is not keeping the contents!)
So I want to understand if (and how and why) program > /tmp/mystdout
has worse performance in any aspects than program > /dev/null
.
Inspecting it with lsof
both cases looks very identical.
PS: worse performance: I'm interested if by-design any of those 2 above has performance drawback(s) against the other.
Your second approach doesn't work at all, for reasons unrelated to performance. FIFOs have a finite buffer size, and if you have a program that writes to one without anything reading from it, eventually the buffer will fill up, and then your program will just hang until you attach to it.