From 8f3b31466fbe6e1fec0e7dedd2396c70504a2eb2 Mon Sep 17 00:00:00 2001 From: Kevin Lange Date: Mon, 6 May 2013 01:29:04 -0700 Subject: [PATCH] add kill app --- userspace/core/kill.c | 50 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 userspace/core/kill.c diff --git a/userspace/core/kill.c b/userspace/core/kill.c new file mode 100644 index 00000000..8a492320 --- /dev/null +++ b/userspace/core/kill.c @@ -0,0 +1,50 @@ +/* + * kill + * + * Send a signal to another process + */ +#include +#include +#include +#include +#include + +void usage(char * argv[]) { + printf( + "kill - send a signal to another process\n" + "\n" + "usage: %s [-\033[3mx\033[0m] \033[3mprocess\033[0m\n" + "\n" + " -h --help \033[3mShow this help message.\033[0m\n" + " -\033[3mx\033[0m \033[3mSignal number to send\033[0m\n" + "\n", + argv[0]); +} + +int main(int argc, char * argv[]) { + int signum = SIGKILL; + int pid = 0; + + if (argc < 2) { + usage(argv); + return 1; + } + + if (argc > 2) { + if (argv[1][0] == '-') { + signum = atoi(argv[1]+1); + } else { + usage(argv); + return 1; + } + pid = atoi(argv[2]); + } else if (argc == 2) { + pid = atoi(argv[1]); + } + + if (pid) { + kill(pid, signum); + } + + return 0; +}