How can I keep the program running in the background even when the ssh connection is closed?

For Unix, Linux-like server maintenance is often done through ssh, and some operations are time-consuming, such as updating programs. If the ssh connection is disconnected at this point, the updater will be interrupted. How to ensure that the update process can still be kept running after disconnecting ssh? There are two ways:

 

(1)nohup

 

#nohup app name&

 

After that, if you disconnect ssh, the program still runs. The disadvantage of this method is that the application has no interactive interface, the output of the program will be output in a xxx.out file, and the end of the program cannot be controlled on the interface in the future. Must pass the kill method. Therefore, this method is very simple and rude, and is rarely used.

 

(2)screen

 

#screen

Enter the Screen sub-interface after pressing Enter. At this time, the putty title bar will indicate that it is in the sub-interface state, and then run your program.

#application name

Then press Ctrl+A and lift it up, and then press the d key. At this time, switch back to the main interface, and Putty's window title bar will also indicate.

#Do other operations, or exit

 

At this point, ssh is disconnected, and the program is still running. After re-ssh connection later, enter

#screen -ls

, to view the code name of the sub-interface, and then enter

#screen -r Subscreen codename

You can view the sub-interface where your program was running.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326010847&siteId=291194637