Keep processes running in the background and even after SSH session disconnects

tottoramen發表於2020-12-13

I started running a computation-intensive python script on a SSH session. But the session kept disconnecting and I lost all my results all the time. The solution was to run the script in the background without interrupting.

Linux nohup Command works perfectly in this scenario. 

The syntax is:

nohup python3 code.py &

The & makes it run in the background so we can keep interacting with the terminal.

If you want to bring it back to foreground, use fg. If you want to bring it back to foreground, use Ctrl+z. But it's stopped after Ctrl+zbg is to make it run again.

 

相關文章