Subject: Ignore case in pgrep(1)
To: None <tech-userlevel@netbsd.org>
From: Jonathan Perkin <jonathan@perkin.org.uk>
List: tech-userlevel
Date: 03/10/2005 07:37:04
--8vCeF2GUdMpe9ZbK
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Hi,
On a number of occasions in the past I wished pgrep could ignore case,
as I've been trying to find a process which I am not entirely sure the
name of. I've been using the attached patch, and am wondering if
anyone else would find this useful and worth committing to NetBSD?
Thanks,
--
Jonathan Perkin The NetBSD Project
http://www.perkin.org.uk/ http://www.netbsd.org/
--8vCeF2GUdMpe9ZbK
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="pkill.diff"
Index: pkill.1
===================================================================
RCS file: /cvsroot/src/usr.bin/pkill/pkill.1,v
retrieving revision 1.8
diff -u -r1.8 pkill.1
--- pkill.1 14 Feb 2003 15:59:18 -0000 1.8
+++ pkill.1 10 Mar 2005 07:29:48 -0000
@@ -42,7 +42,7 @@
.Nd find or signal processes by name
.Sh SYNOPSIS
.Nm pgrep
-.Op Fl flnvx
+.Op Fl filnvx
.Op Fl G Ar gid
.Op Fl P Ar ppid
.Op Fl U Ar uid
@@ -107,6 +107,8 @@
or
.Nm pkill
command.
+.It Fl i
+Ignore case distinctions in both the process table and the supplied pattern.
.It Fl l
Long output.
Print the process name in addition to the process ID for each matching
Index: pkill.c
===================================================================
RCS file: /cvsroot/src/usr.bin/pkill/pkill.c,v
retrieving revision 1.8
diff -u -r1.8 pkill.c
--- pkill.c 2 Mar 2005 15:31:44 -0000 1.8
+++ pkill.c 10 Mar 2005 07:29:49 -0000
@@ -94,6 +94,7 @@
int longfmt;
int matchargs;
int fullmatch;
+int cflags = REG_EXTENDED;
kvm_t *kd;
pid_t mypid;
@@ -156,7 +157,7 @@
criteria = 0;
- while ((ch = getopt(argc, argv, "G:P:U:d:fg:lns:t:u:vx")) != -1)
+ while ((ch = getopt(argc, argv, "G:P:U:d:fg:ilns:t:u:vx")) != -1)
switch (ch) {
case 'G':
makelist(&rgidlist, LT_GROUP, optarg);
@@ -182,6 +183,9 @@
makelist(&pgrplist, LT_PGRP, optarg);
criteria = 1;
break;
+ case 'i':
+ cflags |= REG_ICASE;
+ break;
case 'l':
if (!pgrep)
usage();
@@ -246,7 +250,7 @@
* Refine the selection.
*/
for (; *argv != NULL; argv++) {
- if ((rv = regcomp(®, *argv, REG_EXTENDED)) != 0) {
+ if ((rv = regcomp(®, *argv, cflags)) != 0) {
regerror(rv, ®, buf, sizeof(buf));
errx(STATUS_BADUSAGE, "bad expression: %s", buf);
}
--8vCeF2GUdMpe9ZbK--