Add -y option, and -s signum. Default to SIGTERM, document this.
This commit is contained in:
parent
64cf549998
commit
b33d3eefbb
@ -1,5 +1,5 @@
|
||||
--- Makefile.orig Tue Sep 29 19:39:07 1998
|
||||
+++ Makefile Tue Sep 29 19:39:07 1998
|
||||
--- Makefile.orig Sun May 30 15:47:24 1999
|
||||
+++ Makefile Sun May 30 15:47:24 1999
|
||||
@@ -0,0 +1,3 @@
|
||||
+PROG = zap
|
||||
+
|
||||
|
@ -1,5 +1,5 @@
|
||||
--- system.c.orig Sat Dec 20 11:08:08 1997
|
||||
+++ system.c Tue Sep 29 19:39:07 1998
|
||||
+++ system.c Sun May 30 15:47:24 1999
|
||||
@@ -8,7 +8,7 @@
|
||||
char *s;
|
||||
{
|
||||
|
@ -1,5 +1,5 @@
|
||||
--- zap-slashproc.c.orig Tue Sep 29 19:39:07 1998
|
||||
+++ zap-slashproc.c Tue Sep 29 19:39:07 1998
|
||||
--- zap-slashproc.c.orig Sun May 30 15:47:25 1999
|
||||
+++ zap-slashproc.c Sun May 30 15:47:25 1999
|
||||
@@ -0,0 +1,148 @@
|
||||
+/*
|
||||
+ * zap -- fast kill by name using SVR4 /proc
|
||||
@ -8,7 +8,7 @@
|
||||
+ * The UNIX Programming Environment, 1984.
|
||||
+ */
|
||||
+
|
||||
+#ident "$Id: patch-03,v 1.1.1.1 1998/09/29 23:59:18 ian Exp $"
|
||||
+#ident "$Id: patch-03,v 1.2 1999/05/30 20:44:39 ian Exp $"
|
||||
+
|
||||
+#include <stdio.h>
|
||||
+#include <dirent.h>
|
||||
|
@ -1,6 +1,6 @@
|
||||
--- zap.1.orig Tue Sep 29 19:39:08 1998
|
||||
+++ zap.1 Tue Sep 29 19:42:05 1998
|
||||
@@ -0,0 +1,38 @@
|
||||
--- zap.1.orig Sun May 30 15:47:25 1999
|
||||
+++ zap.1 Sun May 30 16:33:31 1999
|
||||
@@ -0,0 +1,49 @@
|
||||
+.Dd 1984
|
||||
+.Os OpenBSD 2.3
|
||||
+.Dt ZAP 1 UPM
|
||||
@ -8,20 +8,31 @@
|
||||
+.Nm zap
|
||||
+.Nd interactive process killer
|
||||
+.Sh SYNOPSIS
|
||||
+.Nm zap [string [...]]
|
||||
+.Nm zap [-s NUM] [-y] string [...]]
|
||||
+.Sh DESCRIPTION
|
||||
+.Nm Zap
|
||||
+takes zero or more strings, looks for each in the output of a
|
||||
+takes one or more strings, looks for each in the output of a
|
||||
+.Nm ps
|
||||
+command that it runs, and for each process whose
|
||||
+.Nm ps
|
||||
+line matches the string, prints the line as a prompt.
|
||||
+If you reply with a
|
||||
+.Nm y,
|
||||
+the program attempts to deliver a signal to the given process.
|
||||
+If no
|
||||
+the program attempts to deliver a signal SIGERM to the given process.
|
||||
+If a zero-length
|
||||
+.Nm string
|
||||
+is given, then every process will be prompted for.
|
||||
+.PP
|
||||
+The
|
||||
+.B -y
|
||||
+option tells the program to just do it, not to ask for confirmation.
|
||||
+It makes the program non-interactive.
|
||||
+.PP
|
||||
+The
|
||||
+.B -s
|
||||
+.I signum
|
||||
+option takes a numeric (only) argument, which is the signal number
|
||||
+to send. In the absence of this option, SIGTERM is sent.
|
||||
+.Sh EXAMPLES
|
||||
+.Nm zap pppd
|
||||
+.br
|
||||
|
@ -1,6 +1,6 @@
|
||||
--- zap.c.orig Sat Dec 20 11:08:09 1997
|
||||
+++ zap.c Fri Oct 2 14:50:18 1998
|
||||
@@ -2,18 +2,22 @@
|
||||
+++ zap.c Sun May 30 16:19:56 1999
|
||||
@@ -2,36 +2,81 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
@ -18,29 +18,81 @@
|
||||
+main(int argc, char **argv)
|
||||
{
|
||||
FILE *fin, *popen();
|
||||
char buf[BUFSIZ];
|
||||
int pid;
|
||||
- char buf[BUFSIZ];
|
||||
- int pid;
|
||||
+ char buf[BUFSIZ]; /* a line to read */
|
||||
+ int errors = 0; /* for getopt */
|
||||
+ int c = 0; /* from getopt */
|
||||
+ extern int optind; /* from getopt */
|
||||
+ extern char* optarg;/* from getopt */
|
||||
+ int pid; /* target PID */
|
||||
+ int interact = 1; /* ? ask : just do it */
|
||||
+ int debug = 0; /* print debugging? (unused) */
|
||||
+ int signum = SIGTERM; /* how shall I tell thee? */
|
||||
|
||||
progname = argv[0];
|
||||
+ progpid = getpid();
|
||||
+
|
||||
+ while ((c = getopt(argc, argv, "ds:y")) != EOF) {
|
||||
+ switch (c) {
|
||||
+ case 's':
|
||||
+ signum = atoi(optarg); /* TODO name lookup like kill(1) */
|
||||
+ break;
|
||||
+ case 'd':
|
||||
+ ++debug;
|
||||
+ break;
|
||||
+ case 'y':
|
||||
+ interact = 0;
|
||||
+ break;
|
||||
+ case '?':
|
||||
+ default:
|
||||
+ errors++;
|
||||
+ break;
|
||||
+ }
|
||||
+ }
|
||||
+ if (errors || (argc-optind<1)) {
|
||||
+ (void) fprintf(stderr, "usage: %s [-s signum] processname ...\n", progname);
|
||||
+ exit(2);
|
||||
+ }
|
||||
+
|
||||
if ((fin = popen(ps, "r")) == NULL) {
|
||||
fprintf(stderr, "%s: can't run %s\n", progname, ps);
|
||||
exit(1);
|
||||
@@ -21,12 +25,14 @@
|
||||
}
|
||||
fgets(buf, sizeof buf, fin); /* get header line */
|
||||
fprintf(stderr, "%s", buf);
|
||||
while (fgets(buf, sizeof buf, fin) != NULL)
|
||||
- while (fgets(buf, sizeof buf, fin) != NULL)
|
||||
- if (argc == 1 || strindex(buf, argv[1]) >= 0) {
|
||||
+ if (argc == 1 ||
|
||||
+ (strindex(buf, argv[1]) >= 0 && atoi(buf) != progpid)) {
|
||||
buf[strlen(buf)-1] = '\0'; /* suppress \n */
|
||||
fprintf(stderr, "%s? ", buf);
|
||||
if (ttyin() == 'y') {
|
||||
sscanf(buf, "%d", &pid);
|
||||
- buf[strlen(buf)-1] = '\0'; /* suppress \n */
|
||||
- fprintf(stderr, "%s? ", buf);
|
||||
- if (ttyin() == 'y') {
|
||||
- sscanf(buf, "%d", &pid);
|
||||
- kill(pid, SIGKILL);
|
||||
+ if (kill(pid, SIGKILL)<0)
|
||||
+
|
||||
+ /* Read a line from ps, process it. */
|
||||
+ while (fgets(buf, sizeof buf, fin) != NULL) {
|
||||
+ buf[strlen(buf)-1] = '\0'; /* suppress \n */
|
||||
+ if (strstr(buf, argv[optind]) != NULL &&
|
||||
+ (pid = atoi(buf)) != progpid) {
|
||||
+
|
||||
+ fprintf(stderr, "%s", buf);
|
||||
+
|
||||
+ if (interact) {
|
||||
+ fprintf(stderr, "? ");
|
||||
+ if (ttyin() == 'y') {
|
||||
+ if (kill(pid, signum)<0)
|
||||
+ perror(buf);
|
||||
+ }
|
||||
+ } else {
|
||||
+ fprintf(stderr, "\n");
|
||||
+ if (kill(pid, signum)<0)
|
||||
+ perror(buf);
|
||||
}
|
||||
}
|
||||
+ }
|
||||
exit(0);
|
||||
}
|
||||
|
||||
#include "ttyin2.c"
|
||||
-#include "strindex.c"
|
||||
#include "efopen.c"
|
||||
|
Loading…
Reference in New Issue
Block a user