Remember that the shell sits there listening to what you type,
and calling other programs to do jobs that it doesn't have
built-in commands to do.
Normally, when the shell calls another program, it waits for
the other program to finish. All the ampersand (
&
) at the end of a
command line does is tell the shell not to wait.
Both the Bourne shell and the C shell allow background
processing.
But, on UNIX systems that have
job control (
12.1
)
,
the C shell,
bash
and
ksh
give you a lot of extra
capabilities for manipulating background processes.
Here's the tip of the iceberg:
-
If you forget to put a job into the background, you can stop it
on the fly with a
suspend signal (
38.1
)
by typing CTRL-z.
Then use the
bg
command to put it into the
background and restart it:
%
find /usr -name tim -print > mine
[CTRL-z]
Stopped
%
bg
[1] find /usr -name tim -print > mine &
-
You can bring
the current background job (
12.3
)
into the foreground with
the
fg
command.
This is handy when UNIX stops the background job that needs input from
your keyboard (you can't type to jobs running in the background).
-
If you have a lot of background processes running, you can use
the
jobs
command to list them all, and then bring a selected job into
the foreground by job number. You can also kill jobs by job number
rather than by process ID.