Keep running long processes in terminal using Screen

Michael Schmidt
Published: Aug 24, 2024 by Michael Schmidt
Keep running long processes in terminal using Screen

Prerequisites #

Our guides are written with the expectation that the following requirements are met:

Why to use screen? #

Screen is a terminal multiplexer that allows you to run multiple terminal sessions in the background. With Screen, you can detach from a session, leaving processes running in the background, and later reattach to the session without losing any work. This is particularly useful for remote administration over SSH, where maintaining session continuity is crucial.

Key features:

  • Screens can be named, making them easier to manage and close later.
  • It allows running applications in the background without the need to set up a systemd service.
  • Your session remains active even with an unstable network connection.

Important: Screens are not preserved after restarting a server, so they should not be used for permanent workloads.

Install Screen #

It is a simple command, usually already installed on your Ubuntu system:

sudo apt-get install screen -y

Manage Screen sessions #

Create a new session:
screen -S minecraft
Join a session:
screen -r minecraft
Leave a new session:

Press CRTL + A then CRTL + D

[detached from 40103.minecraft]
Terminate/Close a new session:

Press CRTL + D then CRTL + C

[screen is terminating]
List running screens:
screen -ls

Response like: You can join to a screen with using the 40137 ID or the name minecraft

There is a screen on:
        40137.minecraft (08/24/24 08:54:12)     (Detached)
1 Socket in /run/screen/S-root.