summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2020-03-12 20:47:29 -0500
committerJakob Kaivo <jkk@ung.org>2020-03-12 20:47:29 -0500
commit59fbad21c96727767a68ca6c8c4c5a8fad58f7d5 (patch)
tree2bb87ce5d2773767c2cec0df0ae9fc7bf9a00382
parentdec58a24c3bcd41456823328c92f8e9c698a66c3 (diff)
actually kill something
-rw-r--r--kill.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/kill.c b/kill.c
index 31cc706..777f531 100644
--- a/kill.c
+++ b/kill.c
@@ -20,6 +20,8 @@
#include "sh.h"
#include <ctype.h>
#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
#include <signal.h>
#include <unistd.h>
@@ -95,7 +97,20 @@ int kill_main(int argc, char *argv[])
return 0;
}
- printf("%s\n", signame);
+ if (argc <= optind) {
+ fprintf(stderr, "kill: missing operand\n");
+ return 1;
+ }
+
+ int pid = atoi(argv[optind]);
+ for (size_t i = 0; i < nsigs; i++) {
+ if (!strcmp(signame, ksigs[i].name)) {
+ if (kill(pid, ksigs[i].num) != 0) {
+ perror("kill");
+ }
+ }
+ }
- return 0;
+ fprintf(stderr, "kill: invalid signal '%s'\n", signame);
+ return 1;
}