Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 3 Feb 2010 17:00:28 +0200
From:      Eitan Adler <eitanadlerlist@gmail.com>
To:        hackers@freebsd.org
Subject:   [RFC] [patch] pkill verbose option
Message-ID:  <a0777e081002030700l53d9cae2v74a181315ed55277@mail.gmail.com>

next in thread | raw e-mail | index | archive | help

[-- Attachment #1 --]
I added an option to pkill which lists what processes it kills and what
signal is sent. If no signals are sent it prints out the same message
killall does.

[-- Attachment #2 --]
Index: pkill.1
===================================================================
--- pkill.1	(revision 203347)
+++ pkill.1	(working copy)
@@ -122,6 +122,8 @@
 Restrict matches to processes with a real user ID in the comma-separated
 list
 .Ar uid .
+.It Fl V
+Lists which processes action will be taken on and what signal will be sent.
 .It Fl d Ar delim
 Specify a delimiter to be printed between each process ID.
 The default is a newline.
Index: pkill.c
===================================================================
--- pkill.c	(revision 203347)
+++ pkill.c	(working copy)
@@ -105,6 +105,7 @@
 static int	oldest;
 static int	interactive;
 static int	inverse;
+static int	flagPrint = 0;
 static int	longfmt;
 static int	matchargs;
 static int	fullmatch;
@@ -182,7 +183,7 @@
 	pidfilelock = 0;
 	execf = coref = _PATH_DEVNULL;
 
-	while ((ch = getopt(argc, argv, "DF:G:ILM:N:P:SU:ad:fg:ij:lnos:t:u:vx")) != -1)
+	while ((ch = getopt(argc, argv, "DF:G:ILM:N:P:SU:Vad:fg:ij:lnos:t:u:vx")) != -1)
 		switch (ch) {
 		case 'D':
 			debug_opt++;
@@ -272,6 +273,9 @@
 		case 'v':
 			inverse = 1;
 			break;
+		case 'V':
+			flagPrint = 1;
+			break;
 		case 'x':
 			fullmatch = 1;
 			break;
@@ -528,16 +532,26 @@
 	/*
 	 * Take the appropriate action for each matched process, if any.
 	 */
+	int didAction = 0;
 	for (i = 0, rv = 0, kp = plist; i < nproc; i++, kp++) {
 		if (PSKIP(kp))
 			continue;
 		if (selected[i]) {
+			if (flagPrint)
+			{
+				didAction = 1;
+				printf("kill -%d %d\n",signum,kp->ki_pid);
+			}
 			if (inverse)
 				continue;
 		} else if (!inverse)
 			continue;
 		rv |= (*action)(kp);
 	}
+	if (!didAction)
+	{
+		printf("No matching processes belonging to you were found\n");
+	}
 
 	exit(rv ? STATUS_MATCH : STATUS_NOMATCH);
 }

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?a0777e081002030700l53d9cae2v74a181315ed55277>