| 1 |
/* Given a external process' id as argument, the program waits for a set timeout then attempts to abort that process */ |
| 2 |
/* Used by the Mono runtime's crash reporting. */ |
| 3 |
|
| 4 |
#include <stdlib.h> |
| 5 |
#include <stdio.h> |
| 6 |
#include <stdint.h> |
| 7 |
#include <errno.h> |
| 8 |
#include <unistd.h> |
| 9 |
#include "config.h" |
| 10 |
#include <signal.h> |
| 11 |
|
| 12 |
#define TIMEOUT 30 |
| 13 |
|
| 14 |
static char* program_name; |
| 15 |
void program_exit (int exit_code, const char* message); |
| 16 |
|
| 17 |
int main (int argc, char* argv[]) |
| 18 |
{ |
| 19 |
program_name = argv [0]; |
| 20 |
if (argc != 2) |
| 21 |
program_exit (1, "Please provide one argument (pid)"); |
| 22 |
errno = 0; |
| 23 |
pid_t pid = (pid_t)strtoul (argv [1], NULL, 10); |
| 24 |
if (errno) |
| 25 |
program_exit (2, "Invalid pid"); |
| 26 |
|
| 27 |
sleep (TIMEOUT); |
| 28 |
|
| 29 |
/* if we survived the timeout, we consider the Mono process as hung */ |
| 30 |
|
| 31 |
#ifndef HAVE_KILL |
| 32 |
/* just inform the user */ |
| 33 |
printf ("Mono process with pid %lu appears to be hung", (unsigned long)pid); |
| 34 |
return 0; |
| 35 |
#else |
| 36 |
printf ("Mono process hang detected, sending kill signal to pid %lu\n", (unsigned long)pid); |
| 37 |
return kill (pid, SIGKILL); |
| 38 |
#endif |
| 39 |
} |
| 40 |
|
| 41 |
void program_exit (int exit_code, const char* message) |
| 42 |
{ |
| 43 |
if (message) |
| 44 |
printf ("%s\n", message); |
| 45 |
printf ("Usage: '%s [pid]'\t\t[pid]: The id for the Mono process\n", program_name); |
| 46 |
exit (exit_code); |
| 47 |
} |