Skip to main content

From my understanding, jobs are pipelines (http://web.mit.edu/gnu/doc/html/features_5.htmljobs are pipelines) started from a certain shell and you can manage these jobs (fgfg, bgbg, ctrlCtrl-zZ) from within this shell. A job can consist of multiple processes/commands.

My question is what happens to these jobs when the original, containing shell exits? Suppose huponexit is not set so background processes keep running after the shell exits.

Suppose I have done:

run.sh | grep 'abc' &

[1] job_id

$ run.sh | grep 'abc' & [1] job_id 

Then I exit this shell. I'll enter a new shell and run jobs and see nothing obviously. But I can do ps aux | grep run.sh and see this process running and I'll also do ps aux | grep grep and see the process for grep 'abc' running too.

Is there a way to just get the job ID for the full pipeline so that I can kill it in one go, or do I have to kill all the processes separately from another shell once I have exited the original shell? ( II have tried the latter and it works, but it seems like a hassle to keep track of all the processes.  )

From my understanding, jobs are pipelines (http://web.mit.edu/gnu/doc/html/features_5.html) started from a certain shell and you can manage these jobs (fg, bg, ctrl-z) from within this shell. A job can consist of multiple processes/commands.

My question is what happens to these jobs when the original, containing shell exits? Suppose huponexit is not set so background processes keep running after the shell exits.

Suppose I have done:

run.sh | grep 'abc' &

[1] job_id

Then I exit this shell. I'll enter a new shell and run jobs and see nothing obviously. But I can do ps aux | grep run.sh and see this process running and I'll also do ps aux | grep grep and see the process for grep 'abc' running too.

Is there a way to just get the job ID for the full pipeline so that I can kill it in one go, or do I have to kill all the processes separately from another shell once I have exited the original shell? ( I have tried the latter and it works, but it seems like a hassle to keep track of all the processes.  )

From my understanding, jobs are pipelines started from a certain shell and you can manage these jobs (fg, bg, Ctrl-Z) from within this shell. A job can consist of multiple processes/commands.

My question is what happens to these jobs when the original, containing shell exits? Suppose huponexit is not set so background processes keep running after the shell exits.

Suppose I have done:

$ run.sh | grep 'abc' & [1] job_id 

Then I exit this shell. I'll enter a new shell and run jobs and see nothing obviously. But I can do ps aux | grep run.sh and see this process running and I'll also do ps aux | grep grep and see the process for grep 'abc' running too.

Is there a way to just get the job ID for the full pipeline so that I can kill it in one go, or do I have to kill all the processes separately from another shell once I have exited the original shell? (I have tried the latter and it works, but it seems like a hassle to keep track of all the processes.)

edited tags
Link
Gilles 'SO- stop being evil'
  • 866.2k
  • 205
  • 1.8k
  • 2.3k
Source Link
user2193268
  • 289
  • 1
  • 2
  • 4

What happens to background jobs after exiting the shell?

From my understanding, jobs are pipelines (http://web.mit.edu/gnu/doc/html/features_5.html) started from a certain shell and you can manage these jobs (fg, bg, ctrl-z) from within this shell. A job can consist of multiple processes/commands.

My question is what happens to these jobs when the original, containing shell exits? Suppose huponexit is not set so background processes keep running after the shell exits.

Suppose I have done:

run.sh | grep 'abc' &

[1] job_id

Then I exit this shell. I'll enter a new shell and run jobs and see nothing obviously. But I can do ps aux | grep run.sh and see this process running and I'll also do ps aux | grep grep and see the process for grep 'abc' running too.

Is there a way to just get the job ID for the full pipeline so that I can kill it in one go, or do I have to kill all the processes separately from another shell once I have exited the original shell? ( I have tried the latter and it works, but it seems like a hassle to keep track of all the processes. )