Is dumping to FIFO has more overhead than to /dev/null?

124 Views Asked by At

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:

  1. Starting it as program > /dev/null and use some ptrace later to change the default output when investigation is needed
  2. 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.

1

There are 1 best solutions below

0
On

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.