[Reprinted 1]
System Administrators often need to log on to the server remotely.
Then run some programs on the server.
Sometimes
It takes a long time (more than 12 hours)
This is to exit the Remote Management Terminal if the program is not completed.
Remote programs may be replaced.
In the past, the common solution was to use the nohup command.
However, nohup has many problems.
When Screen
This is all done.
Run the screen command.
Creates a Single Window running shell.
Here
You can run the program you need
Then press Ctrl + a d to exit the newly created window (return to the environment before the screen)
Then, press screen to create a new terminal window.
That's it.
You can create multiple shell windows (these windows can run your own applications)
In this way, you exit the Remote Management window (entering the screen environment)
The windows between your screen Windows will not be closed.
The application running inside will naturally not be used.
Use screen-ls to view all screen sessions
You can use screen-r sessionid to enter a specific screen session specified by sessionid.
When the screen session is no longer used
Screen-r sessionid
Exit to exit
Unix/Linux tool: screen command
Screen usage
It is easy to use screen. You only need to type screen in shell to open a screen session.
In each screen session, all commands start with Ctrl + a (c-.
Now let me briefly introduce the basic commands
C-a c-> Create to open a new window
C-a n-> next, switch to the next window
C-a p-> previous, the previous window
More ..
C-a c-a-> Other, switch between two windows
C-a W-> Windows: list the Windows Enabled
C-a 0-> switch to 0th windows
C-A 1 .. 9-> switch to 1st .. 9 windows
C-a A-> Issue C-A, which can be moved to the beginning of a row in Emacs, VE, Bash, and tcsh.
C-a t-> time: displays the current time and the system load
C-a k (uppercase)-> Kill window, force close the current window
C-A [-> enter copy mode. In copy mode, you can roll back, search,
Copying is like using vi.
C-B backward, Pageup
C-F forward, Pagedown
H (uppercase) high: move the cursor to the upper left corner
L low: move the cursor to the lower left corner.
0 move to the beginning of the row
$ End of line
W forward one word, in the unit of words forward
B backward one word, move backward in the unit of words
Space is the start point of the marked area for the first time, and Space is the end point for the second time
Esc end copy mode
C-a]-> Paste, Paste the content just selected in copy mode
C-? -> Help. Simple instructions are displayed.
C-a d-> detach (May contain multiple windows)
Lost
When C-a d is pressed to detach the screen session in the background, it will return to the status when the screen is not yet in progress.
The process running in each window in the session (either the foreground or the background) continues to be executed, even if logout is not affected.
When login comes in next time:
Screen-ls-> display all screen sessions
Screen-r [keyword]-> select a screen session to resume the dialog.
If the screen-ls contains Attached sessions:
Screen-d [keyword]->Force detach to "take over"
Instance:
I have read so much about the description. Let's end our learning today with an actual example.
After enabling a screen, run Ctrl + a d to edit a file with joe:
[Becks @ ec-base becks] $ screen
[Detached]
At this time, when we run ps-e, we can see that pts/2, the screen I just run is running joe.
6264 pts/2 00:00:00 bash
6354 pts/2 00:00:00 joe
When we want to resume this session, we only need to type screen-r. When you have multiple sessions, the system will prompt you to select one, as shown below:
[Becks @ ec-base becks] $ screen-r
There are several suitable screens on:
6263. pts-1.ec-base (Detached)
6382. pts-1.ec-base (Detached)
Type "screen [-d]-r [pid.] tty. host" to resume one of them.
Enter the pid of the session to restore
[Becks @ becks] $ screen-r 6263
To exit the screen session, just like to exit shell,You only need to enter the exit command, The following prompt will appear after exiting successfully
[Screen is terminating]
[Reprint 2]
Linux screen commands
Function Description:
When you remotely log on to linux using telnet or SSH, if the connection is interrupted abnormally, the system opens a new session and cannot restore the original session.
The session. screen command can solve this problem. The Screen tool is a terminal multi-path Adapter. In essence, this means that you can use a single terminal window to run multiple terminals.
.
Syntax:
Screen [-amrvx-ls-Wipe] [-D <job Name>] [-H <number of rows>] [-r <job Name>] [-S] [-S <job Name>]
Note:
Screen is a multi-window hypervisor. The so-called window refers to a full-screen text screen. The screen program is usually used only when you use Telnet to log on to the host or when you use an older terminal.
Parameters:
-A adjusted all windows to the current terminal size.
-D <job Name>: offline the specified screen job.
-H <number of rows> specifies the number of buffer rows in the window.
-M creates a new screen job even if the screen job is already in the job.
-R <job Name> restores an offline screen job.
-R first tries to restore the offline job. If an offline job cannot be found, a new screen job is created.
-S specifies the shell to be executed when a new window is created.
-S <job Name> specifies the name of the screen job.
-V displays the version information.
-X restores the offline screen job.
-Ls or -- List displays all current screen jobs.
-Wipe checks all current screen jobs and deletes unusable screen jobs.
Common screen parameters:
Screen-s yourname-> Create a session named yourname
Screen-ls-> list all current sessions
Screen-r yourname-> return to yourname session
Screen-d yourname-> remote detach a session
Screen-d-r yourname-> end the current session and return to yourname.
In each screen session, all commands start with ctrl + a (C-.
C-? -> Help. Simple instructions are displayed.
C-a c-> Create to open a new window
C-a n-> Next, switch to the Next window
C-a p-> Previous, the Previous window
C-a 0 .. 9-> switch to 0th .. 9 windows
Ctrl + a [Space]-> from the upper window 0 in sequence to the lower window 9
C-a-> switch between the two recently used Windows
C-a x-> lock the current window and use the user password to unlock it.
C-a d-> detach, temporarily leaves the current session, the current screen session (May contain multiple
Windows) is thrown to the background for execution, and will return to the status when the screen is not yet in progress. At this time, every window in the screen session
Processes running in (both the front-end and backend) are still being executed, even if logout is not affected.
C-a z-> put the current session in the background for execution, and use the shell fg command to go back.
C-a w-> Windows: list the windows Enabled
C-a t-> Time: displays the current Time and the system load
C-a K-> kill window, force close the current window