How to Keep Processes Running After Logout Using Screen

From RidgeRun Developer Wiki

Introduction

Screen or GNU Screen is a terminal multiplexer. Basically you can create screen sessions and run processes in a virtual way into the session. Those processes running can run into the Screen you created even if you close your terminal or you logout from it. It is very useful if you are connected remotely into another system and you do not have a good network connection.

Install Linux Screen

sudo apt install screen

Starting Linux Screen

To start a screen session, just run screen app in your terminal:

screen

Then run the application of interest in the background.

./test & 

In case you want to have multiple sessions

You can assign a name to each session in case you have more than one is easier to find and handle them. you can follow the next steps if you want to create a named session:

screen -S "session_name_to_create"

These are some useful commands that can be used to handle windows in Screen app:

   Ctrl+a c Create a new window (with shell)
   Ctrl+a " List all
   Ctrl+a 0 Switch by number 
   Ctrl+a A Rename the current window
   Ctrl+a S Split current region horizontally into two regions
   Ctrl+a | Split current region vertically into two regions
   Ctrl+a tab Switch the input focus to the next region
   Ctrl+a Ctrl+a Toggle between the current and previous region
   Ctrl+a Q Close all regions but the current one
   Ctrl+a X Close the current region

Detach from Linux Screen Process

In case you want to logout the terminal and you want the process to continue running you can detach Screen session:

Ctrl+a d

Reattach to a Linux Screen Process

Once you login again, to resume your screen session use the following command:

screen -r

More information

Screen Manual