next up previous
Next: Subprocesses Up: Shells Previous: Pipes

Running Commands in the Background

Commands may be run in the background by adding an ampersand to the end of the command. Use the jobs builtin to see what's running, or top to see the most active processes on the system.
1$ find ~ -name \*.c >c-files &
[1] 30384
2$ make -C pub >make.log 2>&1 &
[2] 30385
3$ jobs
[1]- 30384 Running                 find ~ -name \*.c >c-files &
[2]+ 30385 Running                 make -C pub >make.log 2>&1 &

Jobs can be referred to by their process id (30384 and 30385), or by their job number (%1 and %2). (Job numbers are known only by the parent shell, but process ids are system-wide.)

Foreground jobs may be interrupted with C-z. That job may be placed in the background by typing bg. The job will halt when it requests input or displays output (unless it has been redirected). The job may be killed with kill pid.

1$ find / -name \*bogus >|~/tmp/bogus-finds+
  (C-z)
[1]+  Stopped         find / -name \*bogus >|~/tmp/bogus-finds
2$ bg
[1]+ find / -name \*bogus >|~/tmp/bogus-finds &
3$ kill %1
[1]+  Terminated      find / -name \*bogus >|~/tmp/bogus-finds



Reece Kimball Hart
1998-03-18