The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <stdlib.h> |
| 3 | #include <errno.h> |
| 4 | |
| 5 | #include <sys/types.h> |
| 6 | #include <signal.h> |
| 7 | |
| 8 | int kill_main(int argc, char **argv) |
| 9 | { |
| 10 | int sig = SIGTERM; |
| 11 | int result = 0; |
| 12 | |
| 13 | argc--; |
| 14 | argv++; |
| 15 | |
| 16 | if(argc >= 2 && argv[0][0] == '-'){ |
| 17 | sig = atoi(argv[0] + 1); |
| 18 | argc--; |
| 19 | argv++; |
| 20 | } |
| 21 | |
| 22 | while(argc > 0){ |
| 23 | int pid = atoi(argv[0]); |
| 24 | int err = kill(pid, sig); |
| 25 | if (err < 0) { |
| 26 | result = err; |
| 27 | fprintf(stderr, "could not kill pid %d: %s\n", pid, strerror(errno)); |
| 28 | } |
| 29 | |
| 30 | argc--; |
| 31 | argv++; |
| 32 | } |
| 33 | |
| 34 | return result; |
| 35 | } |