Jobs in Linux

A job is a conceptual thing in Linux. With Job you can manage your own processes and send them in background and foreground.

A job can be sent in background in 2 ways.

  1. using CTRL+z shorcut key. In this case, job is in suspended mode.
  2. using & at the end of the command in shell. In this case, job is in running status in the background

To view all jobs in the background, you can use “jobs” command.

To get the job in foreground, you need to use “fg” command. This will get the most recent background job to the foreground.
But you can also get specific job to the foreground using below command.

fg %JOB_NUMBER

You can kill the job using below syntax.

kill %JOB_NUMBER

bg command can be used to resume suspended jobs in the background.
Main purpose of sending the job to background is that you can work on multiple jobs at the same time and you do not need to wait for the job to finish before starting new one.

You can use “disown” command to remove specific job from the list of jobs.

“wait” command is used to wait until background jobs have finished.

“suspend” command has the same effect as pressing hotkey “ctrl+z”

You may also like...