Other Applications of Job Control
This section describes other ways in which job control is useful.
Controlling Background Job Output
Putting a command in the background is handy when you want to do other things while the job is running, but the command may write output to the terminal at inconvenient times. If you are editing a file or composing a mail message, you may not want a background job to splatter output all over the screen. Or, if you have multiple background jobs, their output streams may interfere with each other. To avoid these problems, you can use the following command to force background jobs to stop when they are ready to write to the terminal:
% stty tostopWhen you're ready to see the output of a background job that is stopped waiting to write, bring the job to the foreground.
To let background jobs write to the terminal at any time, use the following command:
% stty -tostopThe following command sequence illustrates the difference between stty tostop and stty –tostop:
%stty tostopTurn tostop on %date &Run command in the background [1] 24980 Shell reports the job number and the process ID [1] + Suspended (tty output) date Job stops when ready to produce output %fgBring the job to the foreground date Shell echoes command line Mon Sep 12 11:59:14 CDT 1994 Job writes output %stty -tostopTurn tostop off %date &Run the command in the background [1] 24982 Shell prints the job number and the process ID Mon Sep 12 11:59:21 CDT 1994 Job writes output without stopping ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access