-
-
Save MaskRay/298e87e465f45988d37f to your computer and use it in GitHub Desktop.
gdb on sigint
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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