Screen is an excellent tool for running programs in the background. Typically, you can connect to a session using screen -r
and then close the session with Ctrl + C
. However, if you’ve implemented exception handling (like try-except
) in your Python scripts, you’ll find that this only breaks out of the loop and doesn’t terminate the entire session. In such cases, directly closing a specific session from outside the session is much more convenient.
The command to do this is:
screen -XS test quit
Here, test
is the name of your session. Of course, to view all active sessions, you can use:
screen -ls
Here’s an example sequence of commands:
screen -S test python test.py
screen -ls
screen -XS test quit
screen -ls