Moving a process around
Juggling processes between the foreground and the background can save
you lots of typing and time since you don't have to restart one program
or command every time you want to work with another program or command.
Placing a process in the background with "&"
To place a process in the background immediately, type the ampersand
symbol (&) at the end of the command. The process will
start and run in the background.
For example, if you type
xclock &
you will see a line showing some numbers, and then the system prompt will
reappear. A clock will eventually appear on your screen (if you're on a
workstation). The sequence should look similar to the following
unity% xclock &
[1] 13673
unity%
The number in brackets is the job number. The second number is called
the process ID (PID). Each process has a unique PID which you can use to
reference that particular process.
If you don't type the & to put the process in the background,
the clock will appear, but you will not get the system prompt back and
you will not be able to issue any other commands until you kill or suspend the
xclock process.
Placing a job in the background with bg
To put a process in the background, even after it is running, you must suspend it and then background it. To do this,
type
Control-z (hold down the Control key and press z.)
You will get a message that the process has been suspended. Now type
bg
and press the Return key. The process will be moved to the background.
If you have more than two processes running, it's a good idea to use
the job number or PID to reference which job you want placed in the background.
The syntax for the bg command is
bg %job_number or PID
That is, you have to type bg % and then the job number
or PID. For example
unity% bg %2
[2] oclock &
unity%
Placing a job in the foreground
When a job is suspended or in the background, it can be brought to the
foreground with the fg command. Note that even if a process
is suspended in some way, the act of bringing it to the foreground will
restart it.
The syntax for the fg command is
fg % job_number or PID
That is, you have to type fg % and then the job number
or PID. For example
unity% fg %2
xclock
You'll notice that the prompt does not reappear after foregrounding the
clock. Since the clock is busy ticking the seconds away in the foreground,
you're unable to use the workstation until you either kill or suspend the
process.
Last modified
July 20, 2004
by cawalker
|