[RFC] [patch] pkill verbose option

jhell jhell at DataIX.net
Thu Feb 4 16:52:04 UTC 2010


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Content-ID: <alpine.BSF.2.00.1002041147050.27763 at pragry.qngnvk.ybpny>


On Thu, 4 Feb 2010 11:01, jhell@ wrote:
>
> On Thu, 4 Feb 2010 05:01, eitanadlerlist@ wrote:
>> This patch hijacks pgrep's -l
>> 
> [cut]
>
> This particular section of the patch should probably be left out until its 
> worked over in a way that it does not print the info message if a process has 
> been found and killed already.
>
> if (!didAction && !pgrep)
>   {
>        printf("No matching processes belonging to you were found\n");
>   }
>
>
> Thanks for the re-patch, quick and resourceful... ;)
>
>

The attached patch is for stable/7 and does not have the above printf for 
no matching processes. It also cleans up the formatting a little following 
the rest of the code and adds the -l flag to the usage statement.

This is only the patch for pkill itself and not for the manual page.

;-)


- -- 

  jhell
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.14 (FreeBSD)

iQEcBAEBAgAGBQJLavsEAAoJEJBXh4mJ2FR+WMwH/1FQY4+FV5xLd6Lg2xgjcbG0
ptDjfr5EdIowWeE2EckcmkZGHZa6Z9WL3zcgOHBfJbsm7pchKUoAjzihlk2iW76u
yBHknDs0Wysv7g0y2nA5sDmjAzzJV8xF8W7aGps+eRJYp1dSDQh9h5zRLAKqZXQ+
hmc43ZUOTYsOoMdPcHJUm48og5Q7IiVeh4B7T6PeMaFdolwW8wGwJuXjOzRw4+UH
A6g+bBctFNrLIxj6eb39oxhIXoDv7unwM+JONJKJvtKWOmbVD22VVYSMeNKSOeqX
9SelPiwdBj9ulJfTuRmrpfuPw/J7CpkrIwKsifPqP3DYuKQ8qLiBO/jRJwLNkpA=
=PD/9
-----END PGP SIGNATURE-----
-------------- next part --------------
Index: pkill.c
===================================================================
--- pkill.c	(revision 193627)
+++ pkill.c	(working copy)
@@ -182,7 +182,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:ad:fg:ilj:lnos:t:u:vx")) != -1)
 		switch (ch) {
 		case 'D':
 			debug_opt++;
@@ -245,8 +245,6 @@
 			criteria = 1;
 			break;
 		case 'l':
-			if (!pgrep)
-				usage();
 			longfmt = 1;
 			break;
 		case 'n':
@@ -528,10 +526,15 @@
 	/*
 	 * 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 (longfmt) {
+				didAction = 1;
+				printf("kill -%d %d\n",signum,kp->ki_pid);
+			}
 			if (inverse)
 				continue;
 		} else if (!inverse)
@@ -550,7 +553,7 @@
 	if (pgrep)
 		ustr = "[-LSfilnovx] [-d delim]";
 	else
-		ustr = "[-signal] [-ILfinovx]";
+		ustr = "[-signal] [-ILfilnovx]";
 
 	fprintf(stderr,
 		"usage: %s %s [-F pidfile] [-G gid] [-M core] [-N system]\n"


More information about the freebsd-hackers mailing list