Last Updated on 2021-06-16 by Clay
When we working in Linux OS, maybe we need put some works in the system background. It means even if you closed your terminal, your works are still performed in the background.
This is the instruction I want to record today: use the "screen" instruction to make our program run in the background.
The advantage of "screen" is that we can repeatedly load and check the program screen after closing the terminal. The disadvantage is that we cannot put it in the background when the work is halfway.
Talked too many concepts, let's take a look at the actual use method!
How to use "screen"
If we are use "screen" in our computer the first time, we need to use the following instruction to install "screen":
sudo apt install screen
And then we key in "screen" in terminal, and press "Enter".
screen
Output:
We will enter the real screen.
In screen, we can execute programs just like in the usual Terminal. Let's say I execute a script that keeps adding:
And we tried to close the terminal.
After reopening the Terminal, we can use the following command to see how many screens are not running now:
screen -ls
Output:
There are screens on: 594.tty3.DESKTOP (12/09/2019 07:02:23 PM) (Detached) 555.tty3.DESKTOP (12/09/2019 07:02:16 PM) (Detached) 515.tty3.DESKTOP (12/09/2019 06:57:18 PM) (Detached) 472.tty3.DESKTOP (12/09/2019 06:56:46 PM) (Detached) 424.tty3.DESKTOP (12/09/2019 06:54:23 PM) (Detached)
Here I have 5 Detached screens, and now I want to connect to the program that I just used last, with infinite loops.
screen -r 594
In this way, you can return to half of the terminal screen!