Skip to content

Instantly share code, notes, and snippets.

@MaskRay
Created December 2, 2014 16:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MaskRay/298e87e465f45988d37f to your computer and use it in GitHub Desktop.
Save MaskRay/298e87e465f45988d37f to your computer and use it in GitHub Desktop.
gdb on sigint
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
void sigint(int)
{
pid_t pid = fork();
if (pid == -1)
abort();
else if (pid) {
char s[13];
sprintf(s, "%d", pid);
execlp("gdb", "gdb", "-p", s, NULL);
} else {
setpgid(0, getpid());
kill(getpid(), SIGSTOP);
}
}
int main()
{
signal(SIGINT, sigint);
sleep(1337);
puts("seen after gdb");
sleep(1337);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment