2

In Linux's bash, I know how to start a long running process and send it to the background.

For example run.sh, then press Control+Z, then type bg 1

Sometime I would like to continue do other work, but this background process keep printing to my Putty console - which is annoying.

I know I can start the run.sh &> /tmp/run.sh.log thus pumping all output to /tmp/run.sh.log but sometime I just forgot to do so.

How do I stop that background process from printing to my console?

Rachid K.
  • 4,490
  • 3
  • 11
  • 30
RonPringadi
  • 1,294
  • 1
  • 19
  • 44
  • You wrote the answer: `script &> /to/somewhere`. Don't forget that, you may get logs printed to your `stdout`. – iamauser Jan 25 '18 at 15:52
  • Assume I forget to do so, what is my alternative other then killing the process and start again? – RonPringadi Jan 25 '18 at 15:55
  • Duplicate of : https://stackoverflow.com/questions/593724/redirect-stderr-stdout-of-a-process-after-its-been-started-using-command-lin – iamauser Jan 25 '18 at 16:11

2 Answers2

8

If you have started the process already and want to stop it from printing to stdout, while still keeping it running, you may use:

stty tostop

When you give stty the tostop argument it stops the background processes that try to write to stdout

To enable the process to write again you may use fg.

Original source can be found here

AnythingIsFine
  • 1,777
  • 13
  • 11
1

Control+Z is stopping your job (like pausing it) that's why you don't see the output. fg 1 makes it to reasume To suppress all messages redirect everything to /dev/null

./your_script.sh 2>&1 &

LMC
  • 10,453
  • 2
  • 27
  • 52