Screen Introduction Screen is a free software developed by the GNU project for command line terminal switching. Users can use this software to connect to multiple local or remote command line sessions at the same time and switch between them freely. GNU Screen can be thought of as a command-line interface version of a window manager. It provides a unified interface and corresponding functions for managing multiple sessions. Official website: http://www.gnu.org/software/screen/ GUN Screen: In the Screen environment, all sessions run independently and have their own number, input, output, and window buffer. Users can switch between different windows using shortcut keys and can freely redirect the input and output of each window. Screen Syntax
Importance of screen The importance of screen lies in the fact that it can run on the server all the time without stopping as long as the server is not down or without power outage. In fact, backend engineers often encounter the situation where they need to process some data by executing scripts, but this script may take half a day or several days to execute. Screen is the best choice. After a while, log in to the server to check the running status and whether it has been completed. It is not finished and continues to run. Common parameters of screen The screen command has many parameters. We will only look at the ones that are commonly used.
In each screen session, all commands start with ctrl+a.
Use of screen First simulate a script code that takes a long time to execute test.php <?php sleep(10000); echo 111; ?> The program sleeps for 10000 seconds and then outputs 1111 First create a screen, then execute it and log out screen -S test php test.php Create a screen named test and execute test.php after entering the screen. Then let the script execute in the screen all the time, and press Ctrl+ad to let the script execute in the background of the screen. screen -S test [detached from 3934.test] exit Log out, wait for a while and then log in again to check if the script is still executing ssh screen -ls There are screens on: 3934.test (02/25/2020 10:27:06 PM) (Detached) The screen ID of test is 3934. Connect to the screen and enter screen -r 3934 php test.php You can see that the test.php script is still executing. Execute ctrl+az to execute the script in the background, and then use fg to bring it to the foreground [1]+ Stopped screen -r 3934 Execute fg php test.php Let's look at screen -d and -D Reopen a window, ssh, and execute screen -d 3934 [3934.test detached.] Then check the previous window to see if the screen is disconnected. screen -r 3934 [remote detached from 3934.test] Look again, -D, in the first window In the second window, execute -D screen -D 3934 [3934.test power detached.] Looking at the first window again, you have been forced to log out. screen -r 3934 [remote power detached from 3934.test] Connection to 127.0.0.1 closed. As a developer, you only need to know three commands to meet more than 90% of the usage scope in normal development. screen -ls screen -S screen -R ctrl+ad Common screen operations Create a session (-m forced): screen -dmS session_name # session_name session name Close the session: View all sessions: Enter the session: Summarize This is the end of this article about the screen command in Linux and how to use it. For more information about the linux screen command, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: jQuery implements simple button color change
>>: MySQL 5.7.27 installation and configuration method graphic tutorial
Today is 618, and all major shopping malls are ho...
This article uses examples to describe how to use...
What you will learn 1. Software installation and ...
This article shares the specific code of js to ac...
This article example shares the specific code of ...
Table of contents 1. Overview 2. Use Keepalived t...
1. Download MySQL from the official website: This...
1. Going around in circles After going around in ...
HTML operation principle: 1. Local operation: ope...
Record the installation and configuration method ...
Linux virtual machine: VMware + Ubuntu 16.04.4 Wi...
Copy code The code is as follows: <!--[if IE]&...
Abstract: When people talk about MySQL performanc...
Create Table create table table name create table...
Front-end technology layer (The picture is a bit e...