Using screen

  Administration

Login via ssh and type:

# screen

Now you can perform whatever the action is. In this example, I am running top just for the example.

Then type top:

#top
top - 20:22:27 up 10 days,  3:47,  1 user,  load average: 0.01, 0.04, 0.00
Tasks: 171 total,   1 running, 170 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.1%us,  0.1%sy,  0.0%ni, 99.8%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:   7971616k total,  5512200k used,  2459416k free,   201416k buffers
Swap:  4184928k total,        0k used,  4184928k free,  3597836k cached

Detach the screen out by pressing Ctrl+ a at the same time – release and then press d.:

# ctrl+a - release then press d

This releases the screen and the task so you can do other things while the task runs in the background.

You’re returned to the terminal window from which you launched the screen session. A message tells you that a screen window labeled [detached from 22591.pts-2.px1] has been detached.

You need the number from the start of the window name to reattach it. If you forget it, you can always use the -ls (list) option, as shown below, to get a list of the detached windows:

# screen -ls
There is a screen on:
        22591.pts-2.px1 (01/15/2021 11:10:56 AM)        (Detached)
1 Socket in /run/screen/S-root.

You can check on the task by typing this to resume the screen:

# screen -r 22591

And see’s top…

top - 20:22:27 up 10 days,  3:47,  1 user,  load average: 0.01, 0.04, 0.00
Tasks: 171 total,   1 running, 170 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.1%us,  0.1%sy,  0.0%ni, 99.8%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:   7971616k total,  5512200k used,  2459416k free,   201416k buffers
Swap:  4184928k total,        0k used,  4184928k free,  3597836k cached

When the process ends, you can type exit to exit from the screen. Alternatively, you can press Ctrl+A, and then K to forcibly kill a window.

# exit