MANAGE
MULTIPLE JOBS USING THESE COMMANDS
As a multiuser system, Linux affords users the abilities to log in
more than once as well as run multiple commands at the same time.
While you can easily accomplish this on the desktop using multiple
terminal windows, you can also do it on a single terminal, either
one that's physically in front of you or via ssh.
The bash shell allows users to run commands, suspend them, place them
into the background, and bring background jobs to the foreground.
To suspend a currently running job, press [Ctrl]Z, which opens a shell
prompt. To resume running the job in the foreground, enter fg. To
place the job in the background, type bg.
To see what jobs are currently running, use the jobs command, which
returns output similar to the following:
$ jobs
[1]- Stopped top
[2]+ Stopped man info
This shows that both the top and man commands are running in the background.
The top command has a job ID of 1, and the man command has a job ID
of 2.
To bring the top command to the foreground, execute the following:
$ fg %1
This tells the fg command to bring job ID 1 to the foreground. You
can represent the second job (which has an ID of 2) as %2.
To kill the man command without first bringing it to the foreground,
execute the following:
kill %2
Being able to run multiple commands, all controlled through one terminal,
is exceptionally useful. For example, this can come in handy when
you're compiling something and wish to background it in order to read
some documentation or a man page--or even just execute another command.
|