How to prevent a background process from being stopped after closing SSH client in Linux How to prevent a background process from being stopped after closing SSH client in Linux linux linux

How to prevent a background process from being stopped after closing SSH client in Linux


I would recommend using GNU Screen. It allows you to disconnect from the server while all of your processes continue to run. I don't know how I lived without it before I knew it existed.


When the session is closed the process receives the SIGHUP signal which it is apparently not catching. You can use the nohup command when launching the process or the bash built-in command disown -h after starting the process to prevent this from happening:

> help disowndisown: disown [-h] [-ar] [jobspec ...]     By default, removes each JOBSPEC argument from the table of active jobs.    If the -h option is given, the job is not removed from the table, but is    marked so that SIGHUP is not sent to the job if the shell receives a    SIGHUP.  The -a option, when JOBSPEC is not supplied, means to remove all    jobs from the job table; the -r option means to remove only running jobs.