Sunday, 13 April 2014

Useful examples for job management in Linux


Being able to master the use of background jobs in Linux is very important and is a great way to increase efficiency. Useful commands are outlined below.

When a job is currently running

  • ctrl -z : suspend a job
^Z
[1]+  Stopped                 ./ExampleScript.sh 

  • ctrl -c : terminate a job

Job Management

  • List all jobs e.g.
 $ jobs
[1]+  Running                 ./ExampleScript.sh &


  •  Start a job in the background with <command> & e.g.
 $ ls &
[1] 6460
  • Kill job using kill %jobnumber e.g. 
$ kill %1
$ jobs
[1]+  Terminated              ./ExampleScript.sh

For a suspended job

  • Continue job in background : bg %jobnumber :
 $ bg %1
[1]+ ./ExampleScript.sh &

  • Bring job to foreground : fg %jobnumber e.g.
$ fg %1
./ExampleScript.sh



No comments:

Post a Comment