Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to quit screen session. For this, I use screen -S session_name -X quit. This works well, but not like I would.

The program running in screen has a handler for SIGTERM, and I really need this handler to execute, so that it can perform proper cleanup. However, running screen -S session_name -X quit results in the program quitting without having its handler invoked.

A simple kill $(pidof bla) results in the invocation of my handler, proper cleaning, and finally the closing of the screen session.

However, I'd like to be able to stop all this by closing the screen using its session's name, and letting it "forward" the SIGTERM signal.

Any help appreciated, thanks.

share|improve this question
I don't see any other way than a script that read the tree of process spawned from the original screen (session should match PID) and send SIGTERM to all process starting with leaves. At the end of the script, just send the screen quit command. – mveroone Aug 13 '13 at 14:38
up vote 2 down vote accepted

The solution I came with is inspired by the one suggested by @Kwaio. I my case, I only have one process that is interested in receiving the SIGTERM signal. This process already forward it to its children.

This assumes that there is only one screen session with a given name.

kill $(ps h --ppid $(screen -ls | grep session_name | cut -d. -f1) -o pid)
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.