I am running my program using screen and GDB.
How I run my program:

screen -dmS adapter "./run-adapter.sh"

In run-adapter.sh

gdb -ex "handle SIGPIPE nostop noprint pass" -ex run -args ./Adapter adapter.conf

The problem is when I try to exit my program by screen:

screen -X -S adapter quit

The screen is terminated nicely, but the program and its GDB are still remaining (checked by ps aux command). Are there any ways to exit them when my screen is terminated?

Edited: As MarkPlotnick requested, my screen is Screen version 4.00.03d (FAU) 23-Oct-06 and GDB is GNU gdb (GDB) 7.7.
Output of grep Sig /proc/$(pgrep Adapter)/status:

SigPnd: 0000000000040000
SigBlk: 0000000000000000
SigIgn: 0000000001001000
SigCgt: 0000000180000620
  • What happens when you kill as opposed to exit? – Raman Sailopal Oct 4 '17 at 12:25
  • 1
    What happens if your script has the line gdb -ex "handle SIGPIPE nostop noprint pass" -ex run -ex quit -args ./Adapter adapter.conf – Mark Plotnick Oct 4 '17 at 16:18
  • @RamanSailopal Yes I can kill the process and its GDB, but I am wondering is there any less ugly way. – Anh Tuan Oct 5 '17 at 6:41
  • @MarkPlotnick Thank you, it worked if I add "-ex quit". Can you post your comment as an answer so I can accept it? – Anh Tuan Oct 5 '17 at 6:55
  • I'd like to be able to explain in my answer why your program and gdb don't exit on their own when screen causes a SIGHUP to be sent to them. Can you tell us what version of gdb and screen you're using, and the output of grep Sig /proc/$(pgrep Adapter)/status ? – Mark Plotnick Oct 5 '17 at 10:59

As suggested by MarkPlotnick's comment, I add -ex quit in gdb command and it worked in OpenSUSE 13.1. The full execution command is:

gdb -ex "handle SIGPIPE nostop noprint pass" -ex run -ex quit -args ./Adapter adapter.conf

And to quit screen with gdb automatically exit, I use:

screen -X -S adapter quit

Unfortunately, the same commands didn't work when I upgraded OS to OpenSUSE 42.2. After a little of investigating, now I can exit with:

screen -X -S adapter stuff "^C" screen -X -S adapter quit

The stuff command will send a Ctrl-C signal (SIGINT) to terminate the adapter process. After that we can quit normally by calling screen ... quit.

PS: The -ex quit option in gdb command isn't necessary anymore if we call screen ... stuff.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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