I often want to run commands or files, e.g. python scripts, and keep them running after my terminal session is closed.

There’s a handy tool to do this called screen.

It’s quick to install.

apt-get install screen

Then, issuing the command ‘screen’ before your command line entry will run with the screen utility. There are a few things you need to know about using screen.

Ctrl a c – Creates a new screen session so that you can use more than one screen session at once.
Ctrl a n – Switches to the next screen session (if you use more than one).
Ctrl a p – Switches to the previous screen session (if you use more than one).
Ctrl a d – Detaches a screen session (without killing the processes in it)

For example.

screen path/to/pythonscript.py
Ctrl a d

The process is running in the background. You can check if it is running by looking at the running processes.

screen -ls

Comments are closed.

Post Navigation