Guest User

Untitled

a guest
Feb 23rd, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. #include <unistd.h>
  2. #include <stdio.h>
  3. #include <sys/syscall.h>
  4. #include <sys/types.h>
  5. #include <sys/signal.h>
  6.  
  7. #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
  8.  
  9. // List common use signal names
  10. static const struct signal_name {
  11. const char *name;
  12. int sig;
  13. } signal_names[] = {
  14. { "HUP", SIGHUP },
  15. { "INT", SIGINT },
  16. { "QUIT", SIGQUIT },
  17. { "ILL", SIGILL },
  18. { "TRAP", SIGTRAP },
  19. { "ABRT", SIGABRT },
  20. { "FPE", SIGFPE },
  21. { "KILL", SIGKILL },
  22. { "USR1", SIGUSR1 },
  23. { "SEGV", SIGSEGV },
  24. { "USR2", SIGUSR2 },
  25. { "PIPE", SIGPIPE },
  26. { "ALRM", SIGALRM },
  27. { "TERM", SIGTERM },
  28. { "CONT", SIGCONT },
  29. { "STOP", SIGSTOP },
  30. };
  31.  
  32. int signame_to_num(char *name) {
  33. size_t n;
  34.  
  35. if(isdigit(*name)) {
  36. return atoi(name);
  37. }
  38.  
  39. if(!strncasecmp(name, "sig", 3))
  40. name += 3;
  41.  
  42. for(n = 0; n < ARRAY_SIZE(signal_names); n++) {
  43. if(!strncasecmp(signal_names[n].name, name)) {
  44. return signal_names[n].sig;
  45. }
  46. }
  47.  
  48. return -1;
  49. }
  50.  
  51. int main(int argc, char *argv[])
  52. {
  53. int sig = SIGTERM;
  54. int tgid = -1;
  55. int tid;
  56.  
  57. if (argc != 4) {
  58. printf("Usage: %s SIGNAL|SIGNUM <tgid> <tid>\n", argv[0]);
  59. return 1;
  60. }
  61.  
  62. sig = signame_to_num(argv[1]);
  63. tgid = atoi(argv[2]);
  64. tid = atoi(argv[3]);
  65.  
  66. return syscall(SYS_tgkill, tgid, tid, sig);
  67. }
Add Comment
Please, Sign In to add comment