Many of my friends may have a headache for some long-running tasks in the actual linux server management work. when something leaves, we turn off the connection terminal and disconnect SSH, the program running just now is also automatically interrupted. Next we will introduce how to keep our program running after disconnecting SSH...
Many of my friends may have a headache for some long-running tasks in the actual linux server management work. when something leaves, we turn off the connection terminal and disconnect SSH, the program running just now is also automatically interrupted. Next we will introduce how to keep our program running after disconnecting SSH.
1. use nohup to keep the program running in the background
Common commands: nohup./home/nginx. sh &
* If the job runs successfully, the standard output will be redirected to the nohup. out file in the current directory by default. you can view the running progress of this file;
2. use screen to run the program in the background
Screen is a window manager that allows multiple processes to take advantage of one physical terminal. Screen has the concept of session. you can create multiple screen windows in one screen session, just like operating a real telnet/SSH connection window in each screen window.
1. install screen
Yum install screen
2. create a screen session
Screen-S wordname
3. temporarily leave and keep the tasks or programs in the screen session
When you need to temporarily exit (the program in the session will not be closed and is still running), you can press the shortcut key Ctrl + a d (that is, press Ctrl, and then press a, d)
4. restore the screen session
When you return, run screen-r wordname to restore the lnmp session created before leaving.
If you forget or do not specify a session name at the beginning, execute screen-ls to list the current session list;
[Root @ LF ~] # Screen-ls
There are screens on:
12738. wordname (Detached)
12839. hte1 (Detached)
2 Sockets in/var/run/screen/S-root
12738. wordname is the session created by screen. The session is restored: screen-r 12738.
5. disable screen sessions
Run: exit
6. remote demonstration
First, execute screen-S test on the server to create a screen session. the audience can link to the remote server and execute screen-x test. the content synchronized with the presenter will appear on the screen of the audience.
7. common shortcut keys
Ctrl + a c create a window in the current screen session
Ctrl + a w Window list
Ctrl + a n next window
Ctrl + a p in the previous window
Ctrl + a 0-9 switch between 0th windows and 9th windows
Extracted from: http://www.vpser.net/manage/screen.html