Closing a Screen Session from Outside the Session
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 session name. In this command, -S selects the session, -X sends a command to it, and quit terminates the session.
To view all active sessions, you can use:
screen -ls
If you only want to leave a session temporarily rather than end it, the more common action inside Screen is Ctrl + A, then D, which detaches the session.
Here’s an example sequence of commands:
screen -S test python test.py
screen -ls
screen -XS test quit
screen -ls

- 原文作者:春江暮客
- 原文链接:https://www.bobobk.com/en/310.html
- 版权声明:本作品采用 知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议 进行许可,非商业转载请注明出处(作者,原文链接),商业转载请联系作者获得授权。