0

A job can be running or stopped (suspended).

When we are talking about foreground jobs and background jobs, are we only talking about running jobs?

Are background jobs and foreground jobs always in running state?

Does it make sense to say whether a stopped job is foreground or background?

2

Background Job : A job which is running background in the same shell. You can use bg command to see any background jobs.

Foreground job : A Job which is running in the same shell right before your eyes.

Suspended Job : Its a stopped/pause job but you can resume their running.

Let me explain with example very clealy

virt00# sleep 180
^Z
zsh: suspended  sleep 180
virt00# jobs
[1]  + suspended  sleep 180
virt00# bg
[1]  + continued  sleep 180
virt00# fg
[1]  + running    sleep 180
^Z
zsh: suspended  sleep 180
virt00# jobs
[1]  + suspended  sleep 180
virt00#

I have started a Job named sleep 180 then I stopped with CTRL+Z . right now my job is in suspended mode.

I see it by typing jobs command. Now I want to resume its running in background so I typed bg command then it will move from suspended state to running state but in background it will run.

now I typed command fg to bring it foreground , now job wont get stepped but it will pull from background jobs queue and push into foreground jobs queue.

So yes background jobs and foreground jobs always are in running state.

  • Did you mean to say that you can use the 'jobs' command to see backgrounded jobs (instead of the bg command)? – Jeff Schaller Feb 29 '16 at 3:59
  • Also, re: your last sentence, a backgrounded job could be suspended (and thus not running ) – Jeff Schaller Feb 29 '16 at 4:01
  • @JeffSchaller No , bg command to see what are the jobs that are running at background jobs , but if you want to see background jobs and suspended jobs you can use jobs command . and how a suspended job can be a background job ? – rɑːdʒɑ Feb 29 '16 at 7:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.