Using and Understanding Job Control
Discussion
Unix is a pre-emptive multitasking operating system. This means that
you can run several different "jobs" at once and they will all run
while you continue to work. The most basic use for the average user
of this is to choose whether or not to run a program and wait for the
result (foreground) or to run a program and keep working while it generates
the results for you (background). There are some tasks that make
no sense to put in the background, and some that make a lot of sense.
Running a job in the foreground.
To run a job in the foreground, you simply run it. An example of this
is doing an ls. If you type
ls you'll get something that looks like this:
bofh% ls
#jobs.html# files.html index.html.bak
. files.html~ index.html~
.. getting_started.html jobs.html
commands.html getting_started.html~ mc.gif
emacs.html index.html paths.html
Since presumeably you need to know what files are in the directory, it
really only makes sense to run this in the foreground.
Starting a job in the background.
To run a job in the background you can either start it that way with
the & or you can interrupt it via
Control-z and then bg.
Top
Top is a utility that shows you all of the jobs running on the system.
This allows you to see jobs that are using a lot of CPU or Memory. If some
process goes awry, it should show up fairly quickly here. A less intuitive
command that you could also use is ps
Other Job Control Commands
- Listing active jobs. (jobs)
- Bringing a job into the foreground.
(fg)
- Putting a job into the background.
(bg)
- Killing a job.
Questions, comments, suggetions or corrections to
bofh@bofh.com
http://www.bofh.com/unix-class/jobs.html