Skip to content

Instantly share code, notes, and snippets.

@apangin
Last active September 3, 2019 16:26
Show Gist options
  • Save apangin/2b8716bbb4efe1239776a18ac04a4e9e to your computer and use it in GitHub Desktop.
Save apangin/2b8716bbb4efe1239776a18ac04a4e9e to your computer and use it in GitHub Desktop.
// 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