## 23.9. Stop Background Output with stty tostop

If you put a job in the background and don't redirect (Section 43.1) its output, text that the job writes to its standard output and standard error comes to your screen. Those messages can mess up the screen while you're using another program. You could lose the (maybe important) messages, too -- they might scroll off your screen and be lost, or your foreground program may clear the screen and erase them.

Many Unix systems have the command stty tostop. Type that command at a prompt, or put it in your .login or .profile file.[69] After that, your shell's background jobs that try to write to your terminal will be stopped. When you want to see the background job's output, bring it into the foreground (with fg).

> [69]This command sets the Unix terminal device driver for all processes started on it. You don't need to set this for subshells (Section 3.3).

How will you know that the background job has been stopped? The shell will print a message like this just before it prints a prompt:

>     [1] + Stopped (tty output)    somejob
>     %

The shell can also interrupt your foreground job with that message as soon as the background job is stopped. To make it do that, set notify (Section 23.8).

In C shell, you can turn off this feature and let background jobs write to your terminal any time with the command:

>     % stty -tostop

In bash, the command is similar:

>     $ stty tostop

-- JP

Copyright © 2003 O'Reilly & Associates. All rights reserved.