Bash Job Control


Display bash built-in help


$ help # show bash built-in help.


Execute commands in foreground and background


$ path/to/program # execute a command in foreground

$ path/to/program & # Execute a command in background

Suspend a command that runs in foreground:
C-z


List current jobs


$ jobs
[1]- Running dev_appserver.py my_app & (wd: ~/devel)
[2]- Running ( while true; do date; sleep 5; done )
[3]+ Stopped sleep 300


It lists three jobs.


Make a job run in foreground


$ fb %1 # %1 is a job spec.


Make a job run in background


$ bg %2


Kill a job


$ kill %1 # %1 is a job spec.

E.g:
$ kill %2
$ jobs
[1]- Running dev_appserver.py my_app & (wd: ~/devel)
[2]+ Terminated ( while true; do date; sleep 5; done )



Wait for background jobs to finish


$ wait # wait for all background jobs to finish.

$ wait %2 # wait for job number 2 to finish


REFERENCE


Advanced Bash-Scripting Guide: Job Control Commands