If I have two backgrounded processes that produce input to STDOUT or STDERR (e.g., two installation scripts), is there an easy way to make these two output streams distinguishable? I guess I can pipe each processes's output through a sed program that prefixes every line of each output with a different tag, but I'm looking for something easier.

  • Why do not use 1>file 2>&1 and use different files for each process? – Romeo Ninov Feb 11 '15 at 19:54
  • 1
    Pipe the output (stdout and stderr) to logger -t {progname} perhaps? – roaima Feb 11 '15 at 20:09
  • How about using a terminal multiplexer like GNU screen or tmux? – user4098326 Feb 13 '15 at 15:01
  • I guess your processes produce output instead of input. IMHO you will not find anything easier that sed or other filter. If you want the mixed output in one terminal window then some filtering with sed is quite easy. You can do something like program1 2>&1 | sed -e 's/^/P1 /' &. – Zaboj Campula Apr 10 '15 at 16:17

The easiest solution would be to start each of the two background jobs and redirect their output to files:

 utility1 >utility1.out 2>utility1.err &
 utility2 >utility2.out 2>utility2.err &

This has the added benefit of not clogging up your terminal with output.

You may obviously redirect both the error and output streams to the same file too:

 utility1 >utility1.out 2>&1 &
 utility2 >utility2.out 2>&1 &

You could also use tmux:

 tmux new "utility1" ';' split "utility2"

tmux will exit as soon as all commands have exited. To avoid that, change "utility" to "utility;read". This will make the pane stay open until you press Enter.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.