How do I use job control in linux?
-
Also see:
How do I run a command in the background on linux?
Man page for bashTaking the
sleep
command example from the article above.If you have a command that has been running on the shell prompt for a long time and you want to stop it (not kill it) you can use Bash job control.
For example the following sleep command will run for 300 seconds on the shell prompt, we press
control-z
, the process is suspended.$ sleep 300 ^Z [1]+ Stopped sleep 300 $
See the job control status.
$ jobs [1]+ Stopped sleep 300 $
To continue running the sleep process in the background. Use the built-in bash command
bg
$ bg %1 [1]+ sleep 300 & $ jobs [1]+ Running sleep 300 & $
To bring back the sleep process into foreground again. It will wait until 300 seconds have been reached and finish. Use the built-in bash command
fg
$ fg %1 sleep 300
The job number in square brackets is incremented for each job. The
%1
is the job specification, job number 2 would be referred to as%2
© Lightnetics 2024