local $SIG{INT} = \&handle_sigint;
sub handle_sigint {
print "received sigint\n";
}
in handle_sigint i would like to print who (pid/process name) sent the signal.
Is there a way to capture that info in perl?
i can do this in C and this is ported to python as a module
I am looking for equivalent in perl
static void csignal_handler(int signum, siginfo_t *siginfo, void *context) {
char *interrupt_msg[150];
if (siginfo->si_pid != 0) {
struct passwd *pwd = getpwuid(siginfo->si_uid);
if (pwd != 0) {
sprintf(interrupt_msg, "Received signal '%d' from process '%d' (%s) of user '%s'\n",
signum, siginfo->si_pid, get_process_name_by_pid(siginfo->si_pid), pwd->pw_name);
} else {
sprintf(interrupt_msg, "Received signal '%d' from process '%d' (%s) of user '%d'\n",
signum, siginfo->si_pid, get_process_name_by_pid(siginfo->si_pid), siginfo->si_uid);
}
printf("%s", interrupt_msg);
}
if (raise_interrupt) {
PyGILState_STATE gstate = PyGILState_Ensure();
PyErr_SetString(PyExc_KeyboardInterrupt, interrupt_msg );
PyGILState_Release(gstate);
} else {
interrupted = 1;
}
}