Last active
September 3, 2019 16:26
-
-
Save apangin/2b8716bbb4efe1239776a18ac04a4e9e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Compile: | |
// gcc -shared -fPIC -olibsighandle.so sighandle.c | |
// | |
// Run: | |
// java -agentpath:/path/to/libsighandle.so ... | |
// kill -37 <pid> | |
#include <signal.h> | |
#include <stdlib.h> | |
#include <unistd.h> | |
static void handler(int sig) { | |
static char message[] = "Signal handler called\n"; | |
write(1, message, sizeof(message) - 1); | |
} | |
__attribute__((visibility("default"))) | |
int Agent_OnLoad(void* vm, char* options, void* reserved) { | |
int sig = options != NULL ? atoi(options) : SIGRTMIN + 3; | |
signal(sig, handler); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment