Go to the previous, next section.

Example of controlling jobs

The following example shows how to suspend a job, run it in the background, check its status, and do something else while waiting for UNIX to say the job running in the background is finished.

rigel% cc -o myprogram myprogram.c
ctrl-Z
Stopped
rigel% bg
[1] cc -o myprogram myprogram.c
rigel% jobs
[1] + Running  cc -o myprogram myprogram.c
rigel% lpq
no entries
[1] + Done quad cc -o myprogram myprogram.c
rigel% ls -F
myprogam*  myprogram.c  test-data

In this example, a user uses the cc command to compile a C program that's in a file named `myprogram.c'. The user decides that the compile job is taking too long and that she wants to have the terminal back while the job completes, so she types ctrl-Z to suspend the job. Because she wants the job to continue in the background, she types the bg command. She then types the jobs command to make sure the job is running. Then she does other work while the job continues running in the background, and UNIX notifies her when her job has finished running.

If compiling this program always takes a long time, it would make sense for the user to run it as a background job in the first place. The following example shows how to do this and then check to see that the job is running.

rigel% cc -o myprogram myprogram.c &
[1] 1962
rigel% jobs
[1] + Running  cc -o myprogram myprogram.c

Go to the previous, next section.