tags 320430 + patch
thanks
hi again,
we better pass %ld to fprintf, instead of %d. Updated diff against
pgrep.c attached.
bye,
- michael
--- procps-3.2.5/pgrep.c 2004-10-19 19:53:47.000000000 +0200
+++ procps-3.2.5.own/pgrep.c 2005-07-29 12:46:21.000000000 +0200
@@ -47,6 +47,7 @@
static int opt_newest = 0;
static int opt_negate = 0;
static int opt_exact = 0;
+static int opt_count = 0;
static int opt_signal = SIGTERM;
static const char *opt_delim = "\n";
@@ -66,7 +67,7 @@
if (i_am_pkill)
fprintf (stderr, "Usage: pkill [-SIGNAL] [-fvx] ");
else
- fprintf (stderr, "Usage: pgrep [-flvx] [-d DELIM] ");
+ fprintf (stderr, "Usage: pgrep [-cflvx] [-d DELIM] ");
fprintf (stderr, "[-n|-o] [-P PPIDLIST] [-g PGRPLIST] [-s SIDLIST]\n"
"\t[-u EUIDLIST] [-U UIDLIST] [-G GIDLIST] [-t TERMLIST] "
"[PATTERN]\n");
@@ -501,7 +502,7 @@
strcat (opts, "ld:");
}
- strcat (opts, "fnovxP:g:s:u:U:G:t:?V");
+ strcat (opts, "cfnovxP:g:s:u:U:G:t:?V");
while ((opt = getopt (argc, argv, opts)) != -1) {
switch (opt) {
@@ -581,6 +582,9 @@
usage (opt);
opt_negate = 1;
break;
+ case 'c':
+ opt_count = 1;
+ break;
// Solaris -x, the standard, does ^(regexp)$
// OpenBSD -x, being broken, does a plain string
case 'x':
@@ -617,13 +621,17 @@
if (kill (procs[i].num, opt_signal) != -1) continue;
if (errno==ESRCH) continue; // gone now, which is OK
fprintf (stderr, "pkill: %ld - %s\n",
- procs[i].num, strerror (errno));
+ procs[i].num, strerror (errno));
}
} else {
- if (opt_long)
- output_strlist (procs);
- else
- output_numlist (procs);
+ if (opt_count) {
+ fprintf(stdout, "%ld\n", procs[0].num);
+ } else {
+ if (opt_long)
+ output_strlist (procs);
+ else
+ output_numlist (procs);
+ }
}
return ((procs[0].num) == 0 ? 1 : 0);
}