How to handle SIGTSTP with GDB


I use Ctrl+Z regularly at the shell to temporarily stop a program and then continue its running using the fg command. However, doing the same in GDB does not work as expected:

  • I press Ctrl+Z. GDB catches it and prints out a message saying SIGTSTP has been received.

  • Typing continue does not continue the execution of the program. The program keeps getting stopped again and prints this message:

(gdb) c

Program received signal SIGTSTP, Stopped (user).
[Switching to Thread 0x7fffe7e28700 (LWP 1492)]
0x00007ffff5b5112d in poll () at ../sysdeps/unix/syscall-template.S:81


To view the signals handled by GDB and how they are handled:

(gdb) info signals
  • To view how a specific signal, say SIGTSTP is handled:
(gdb) info signal SIGTSTP
Signal        Stop  Print   Pass to program Description
SIGTSTP       Yes   Yes Yes     Stopped (user)
  • We can see that by default, this signal is passed to the program. By not passing it to the program, just like what a shell does, our problem is solved. To do this, use the handle command:
(gdb) handle SIGTSTP nopass
  • Type continue now and the program continues from where it was stopped.

Tried with: GDB 7.7.1 and Ubuntu 14.04

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s