Skip Navigation
 Search | Directories | Reference Tools
UW Home > Discover UW > IT Connect > Unix 

Running Jobs in the Background

To run a program in the background, enter the command for that job, followed by the & sign. This returns the Unix prompt to you and executes the job while still allowing you to interact with your terminal. Jobs may be switched from foreground to background and vice versa. When you run a job in the background, the shell will respond with a number. This number is the "process identification number", or PID. It is useful if you want to halt, or `kill' the program.

Background jobs impose just as large a burden on the system as do foreground jobs. It's just that putting a job in background causes everyone to be slowed down a little instead of causing you to have to wait for the job to complete. Therefore, make judicious use of this facility. In particular, users are asked to run only one background job at a time. If you must run several jobs in the background, run them sequentially, not simultaneously. For example, if your programs are `a.out', `b.out' and `c.out', run them in background via the shell command:

        (a.out ; b.out ; c.out) &

To monitor the progress of a background program (and to find out the pid in case you've forgotten it) type `ps'. The response will indicate: the name of the program (under column header COMMAND); its pid (under PID); and the amount of CPU time it has consumed so far (under TIME). If you enter `ps l' you will also be shown the nice value (under NI). Nice is explained in the help text called `bigjobs,' as well as in the `nice' help text. The command `ps x' will list all of your jobs even if they were started in a separate csh or a separate login session.

If you change your mind and decide to wait for a background program to finish running, type `wait'. If you change your mind again, enter control-c. This will interrupt the `wait' but not the program itself - so that you can once again run other commands while the background program continues. When you interrupt the wait, it will report the name and pid(s) of the background process(es). This way is faster than `ps' and does not use so much of the machine's resources. The `jobs' command of the csh job control facilities is even faster.

The job control facilities described in `help job_control' will enable you to quickly kill a background job. If you would rather use the regular kill command, follow instructions below.

Entering control-c to halt a program that is running in the background will not work. Instead, enter the following commands:

     kill pid

(where pid is the pid number of the process) or, if that doesn't work

     kill -9 pid