]> granicus.if.org Git - procps-ng/commitdiff
Add -c count option to pkill
authorCraig Small <csmall@enc.com.au>
Wed, 21 Nov 2012 11:11:17 +0000 (22:11 +1100)
committerCraig Small <csmall@enc.com.au>
Wed, 21 Nov 2012 11:11:17 +0000 (22:11 +1100)
Possibly by a side-effect but pkill -c option used to work which would
print the number of killed processes.  This small change restores this
functionality.

Bug-Debian: http://bugs.debian.org/693783

Signed-off-by: Craig Small <csmall@enc.com.au>
pgrep.1
pgrep.c

diff --git a/pgrep.1 b/pgrep.1
index 1c37e43599d7fd5ae38686741375720675c7960a..0cf8717786dc0d45b0dd2caeaa102432891e3b3c 100644 (file)
--- a/pgrep.1
+++ b/pgrep.1
@@ -49,7 +49,7 @@ only.)
 \fB\-c\fR, \fB\-\-count\fR
 Suppress normal output; instead print a count of matching processes.  When
 count does not match anything, e.g. returns zero, the command will return
-non-zero value.  (\fBpgrep\fP only.)
+non-zero value. 
 .TP
 \fB\-d\fR, \fB\-\-delimiter\fR \fIdelimiter\fP
 Sets the string used to delimit each process ID in the output (by default a
diff --git a/pgrep.c b/pgrep.c
index 4938bc9da53e716e77b61f09128bb3bc500002ba..ce5a58bebf030f4dea2fadb974c471f01682b7a4 100644 (file)
--- a/pgrep.c
+++ b/pgrep.c
@@ -96,8 +96,7 @@ static int __attribute__ ((__noreturn__)) usage(int opt)
        fprintf(fp, _(" %s [options] <pattern>\n"), program_invocation_short_name);
        fputs(USAGE_OPTIONS, fp);
        if (i_am_pkill == 0) {
-               fputs(_(" -c, --count               count of matching processes\n"
-                       " -d, --delimiter <string>  specify output delimiter\n"
+               fputs(_(" -d, --delimiter <string>  specify output delimiter\n"
                        " -l, --list-name           list PID and process name\n"
                        " -v, --inverse             negates the matching\n"), fp);
        }
@@ -105,7 +104,8 @@ static int __attribute__ ((__noreturn__)) usage(int opt)
                fputs(_(" -<sig>, --signal <sig>    signal to send (either number or name)\n"
                        " -e, --echo                display what is killed\n"), fp);
        }
-       fputs(_(" -f, --full                use full process name to match\n"
+       fputs(_(" -c, --count               count of matching processes\n"
+               " -f, --full                use full process name to match\n"
                " -g, --pgroup <id,...>     match listed process group IDs\n"
                " -G, --group <gid,...>     match real group IDs\n"
                " -n, --newest              select most recently started\n"
@@ -620,10 +620,10 @@ static void parse_opts (int argc, char **argv)
                strcat (opts, "e");
        } else {
                /* These options are for pgrep only */
-               strcat (opts, "clad:v");
+               strcat (opts, "lad:v");
        }
                        
-       strcat (opts, "LF:fnoxP:g:s:u:U:G:t:?Vh");
+       strcat (opts, "LF:cfnoxP:g:s:u:U:G:t:?Vh");
        
        while ((opt = getopt_long (argc, argv, opts, longopts, NULL)) != -1) {
                switch (opt) {
@@ -810,6 +810,8 @@ int main (int argc, char **argv)
                                continue;
                        xwarn(_("killing pid %ld failed"), procs[i].num);
                }
+               if (opt_count) 
+                       fprintf(stdout, "%d\n", num);
        } else {
                if (opt_count) {
                        fprintf(stdout, "%d\n", num);