How to use the screen

1 long task

In actual work, we often encounter some tasks that take a long time to complete, such as compressing a 40G directory or copying a large file. These operations take a long time, and the operator generally needs to wait until it is executed. Otherwise, the task execution may fail due to computer lock screen or server ssh connection disconnection.

There is a command in the linux system, screenwhich can solve this problem very well. You can put the executed command into the screen background task through screen, and the screen task is executed as a process in the server background. After setting the screen task, you can exit the server to do other things, wait until the time is almost up, and then check the task placed on the screen.

Under normal circumstances, as long as no one kills your screen task process, and the server does not shut down or restart, the screen task will run smoothly.

The use of screen realizes the unattended operation of long time-consuming tasks, liberates the operator's hands and saves time. It is one of the necessary skills for IT migrant workers.

Let's briefly talk about the usage of screen

2 use

{pid}The pid representing the screen task that appears in the following operations {task_name}represents the task name of the screen

2.1 install screen

yum -y install screen

2.2 Create a screen task

Method 1: Create a screen task with a name

screen -S {
    
    task_name}

Method 2: Create a screen task without a name

screen

After executing the above command, you actually entered the shell environment of the screen. The operations performed at this time are all placed in the screen.

2.3 View screen tasks

Execution -lscan view the pids of all screen tasks in the system

screen -ls

The following 10899 is the pid of the screen task

[root@localhost ~]# screen -ls
There is a screen on:
        10899.task    (Attached)
1 Socket in /var/run/screen/S-root.

2.4 Put the screen task in the background

shortcut key ctrl+ a+d

Another way: open another terminal

screen -d {
    
    pid}
或者
screen -d {
    
    task_name}

2.5 Enter the screen task

screen -r {
    
    pid}
或者
screen -r {
    
    task_name}

2.6 Delete screen task

-rEnter after entering the screen taskexit

2.7 Other shortcut keys

insert image description here

3 Suggestions for use

It is recommended to create a named screen task for later viewing without execution-ls

Guess you like

Origin blog.csdn.net/weixin_43557605/article/details/120265864