Background job in bash is shutting down when the firing window is closed: how to avoid this?

A simple solution is use screen You may need to install it by

apt-get install screen

Then you can use

screen your_command_here

You can use Ctrl-AD to quit screen but keep it running in background. Then you can use

screen -r 

to go back to that screen window.


In bash, you can say:

my_program &
disown -h %1

http://www.gnu.org/software/bash/manual/bashref.html#Job-Control-Builtins


I think your (Tomcat-) processes are killed when the terminal window is closed because the shell, running in the terminal window, is the parent process of your Tomcat process. so when a parent gets killed, all child processes are killed too.

If you don't want this to happen you could try launching your process like this:

nohup /usr/local/tomcat6/bin/startup.sh