RonPringadi
RonPringadi

Reputation: 1494

Preventing background process from writing to console

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?

Upvotes: 2

Views: 5491

Answers (2)

LMC
LMC

Reputation: 12672

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 &

Upvotes: 1

AnythingIsFine
AnythingIsFine

Reputation: 1807

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

Upvotes: 8

Related Questions