Background a running process and log out without it dying off

Not that this is some magical new development,  it’s probably been around for decades, but I find there’s often things I don’t come across until I need them and then wow, there’s already a way to do it.

Your mileage may vary depending on which shell you use, but in CentOS 6 and bash this works great.  I had a process I started, and did not realize it was going to need to run as long as it needs to run.  Rather than lose what it had accomplished over the eight hours since I had started it (it doesn’t use checkpoints so it can’t resume if I restart it later), I was able to:

1) ‘Ctrl-Z’ to interrupt the process (pauses it but leaves it as-is)

2) ‘bg’ to restart it processing in the background.

3) ‘disown -h’ to mark the process as being one that should NOT receive a SIGHUP when you exit the shell.  This is the equivalent of your having run the command under nohup because you intended to log out after executing it.

4) You should now be able to log out and your process keeps going.

Leave a Reply

Your email address will not be published. Required fields are marked *