[hackers] [sbase] add kill, thanks rob || Connor Lane Smith

From: <hg_AT_suckless.org>
Date: Fri, 10 Jun 2011 03:29:16 +0200 (CEST)

changeset: 64:95bb36ed00c9
tag: tip
user: Connor Lane Smith <cls_AT_lubutu.com>
date: Fri Jun 10 02:29:10 2011 +0100
files: Makefile kill.1 kill.c
description:
add kill, thanks rob

diff -r 2122a9ecbeea -r 95bb36ed00c9 Makefile
--- a/Makefile Fri Jun 10 02:00:27 2011 +0100
+++ b/Makefile Fri Jun 10 02:29:10 2011 +0100
@@ -22,6 +22,7 @@
         fold.c \
         grep.c \
         head.c \
+ kill.c \
         ln.c \
         ls.c \
         mkdir.c \
diff -r 2122a9ecbeea -r 95bb36ed00c9 kill.1
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/kill.1 Fri Jun 10 02:29:10 2011 +0100
@@ -0,0 +1,18 @@
+.TH KILL 1 sbase\-VERSION
+.SH NAME
+KILL \- compare two files
+.SH SYNOPSIS
+.B kill
+.RB [ \-s ]
+.RI [ pid ...]
+.SH DESCRIPTION
+.B kill
+sends a
+.I TERM
+signal to the given processes.
+.SH OPTIONS
+.TP
+.BI \-s " signal"
+sends the named signal.
+.SH SEE ALSO
+.IR kill (2)
diff -r 2122a9ecbeea -r 95bb36ed00c9 kill.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/kill.c Fri Jun 10 02:29:10 2011 +0100
@@ -0,0 +1,50 @@
+/* See LICENSE file for copyright and license details. */
+#include <stdlib.h>
+#include <signal.h>
+#include <strings.h>
+#include <unistd.h>
+#include "util.h"
+
+#define LEN(x) (sizeof (x) / sizeof *(x))
+
+struct {
+ const char *name;
+ int sig;
+} sigs[] = {
+#define SIG(n) { #n, SIG##n }
+ SIG(ABRT), SIG(ALRM), SIG(BUS), SIG(CHLD), SIG(CONT), SIG(FPE), SIG(HUP),
+ SIG(ILL), SIG(INT), SIG(KILL), SIG(PIPE), SIG(QUIT), SIG(SEGV), SIG(STOP),
+ SIG(TERM), SIG(TSTP), SIG(TTIN), SIG(TTOU), SIG(USR1), SIG(USR2), SIG(URG),
+#undef SIG
+};
+
+int
+main(int argc, char *argv[])
+{
+ char c, *end;
+ int i, sig = SIGTERM;
+ pid_t pid;
+
+ while((c = getopt(argc, argv, "s:")) != -1)
+ switch(c) {
+ case 's':
+ for(i = 0; i < LEN(sigs); i++)
+ if(!strcasecmp(optarg, sigs[i].name)) {
+ sig = sigs[i].sig;
+ break;
+ }
+ if(i == LEN(sigs))
+ eprintf("%s: unknown signal\n", optarg);
+ break;
+ default:
+ exit(EXIT_FAILURE);
+ }
+ for(; optind < argc; optind++) {
+ pid = strtol(argv[optind], &end, 0);
+ if(*end != '\0')
+ eprintf("%s: not a number\n", argv[optind]);
+ if(kill(pid, sig) == -1)
+ eprintf("kill %d:", pid);
+ }
+ return EXIT_SUCCESS;
+}
Received on Fri Jun 10 2011 - 03:29:16 CEST

This archive was generated by hypermail 2.2.0 : Fri Jun 10 2011 - 03:36:06 CEST