Linux tips-Using screen to manage your remote sessions
When we remotely log on to a Linux server with SSH or telent, run some long tasks, we must wait for the task to complete before leaving the interface. The window cannot be closed or disconnected during this time. Otherwise, the process of this task will not be killed, all by halves, you need to perform the task again.
How to solve this problem?
The first is to understand several concepts:
Process group: A collection of one or more processes, each with a single process group ID, the ID of the process leader process
Session Duration: A collection of one or more process groups with a unique session-first process, session ID as the ID of the process
Session period can have a separate control terminal, the session with the control terminal connected to the first process called the control process, the current and terminal interaction process for the foreground process.
Hang up signal the default action is to terminate the program
When the terminal excuse detects a disconnect from the network connection, it sends the suspend signal to the control process
If the session-time preferred process terminates, the signal is sent to the foreground process group in the session period
When a process exit causes an orphaned process group to be generated, if any orphaned process group is in a stop state, send sighup and sigcont signals to all processes in the process group.
Therefore, when the network disconnects or the terminal window closes, the control process receives a SIGHUP signal exit, which causes the other processes to exit during the session
Method One: Nohup
#nohup Command &
Method Two: Screen
Creen is a window manager that can multiplex a physical terminal across multiple processes.
How to use:
(1), [xuefeng@ku6]# screen
Screen creates a full-screen window that executes the shell, and you can execute any shell as if it were in an SSH window.
(2), [Xuefeng@ku6] #screen VI ABC
Screen to create a separate window session to perform VI ABC, EXIT VI will exit the window
(3), you can also create a new window in the existing Screen session window, type c-a C in the current Sceen window, CTRL + A, and then press the C key. Re-control the programs that are running in each window.
For example, if you are editing vi/tmp/abc in a screen window, and then you need to do something else, you can type c-a d,screen in the screen window and you will be prompted to temporarily interrupt the session. Continue with the previous session, #screen-ls to view the session number. Reconnect the screen-r number.
Note : More wonderful tutorials Please pay attention to the triple computer tutorial section, triple Computer office group: 189034526 welcome you to join