.SH SYNOPSIS
.na
-\fBpgrep\fR [\fB\-flvx\fR] [\fB\-d\ \fIdelimiter\fR] [\fB\-n\fR|\fB\-o\fR] \
+\fBpgrep\fR [\fB\-cflvx\fR] [\fB\-d\ \fIdelimiter\fR] [\fB\-n\fR|\fB\-o\fR] \
[\fB\-P\ \fIppid\fR,...] [\fB\-g\ \fIpgrp\fR,...] [\fB\-s\ \fIsid\fR,...] \
[\fB\-u\ \fIeuid\fR,...] [\fB\-U\ \fIuid\fR,...] [\fB\-G\ \fIgid\fR,...] \
[\fB\-t\ \fIterm\fR,...] [\fIpattern\fR]
to each process instead of listing them on stdout.
.SH OPTIONS
+\-c
+Suppress normal output; instead print a count of matching processes.
.TP
\fB\-d \fIdelimiter\fP
Sets the string used to delimit each process ID in the output (by
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 int opt_lock = 0;
static int opt_case = 0;
if (i_am_pkill)
fprintf (fp, "Usage: pkill [-SIGNAL] [-fvx] ");
else
- fprintf (fp, "Usage: pgrep [-flvx] [-d DELIM] ");
+ fprintf (fp, "Usage: pgrep [-cflvx] [-d DELIM] ");
fprintf (fp, "[-n|-o] [-P PPIDLIST] [-g PGRPLIST] [-s SIDLIST]\n"
"\t[-u EUIDLIST] [-U UIDLIST] [-G GIDLIST] [-t TERMLIST] "
"[PATTERN]\n");
strcat (opts, "ld:");
}
- strcat (opts, "LF:fnovxP:g:s:u:U:G:t:?V");
+ strcat (opts, "LF:cfnovxP:g:s:u:U:G:t:?V");
while ((opt = getopt (argc, argv, opts)) != -1) {
switch (opt) {
exit(EXIT_SUCCESS);
// case 'c': // Solaris: match by contract ID
// break;
+ case 'c':
+ opt_count = 1;
+ break;
case 'd': // Solaris: change the delimiter
opt_delim = strdup (optarg);
break;
procs[i].num, strerror (errno));
}
} else {
- if (opt_long)
- output_strlist(procs,num);
- else
- output_numlist(procs,num);
+ if (opt_count) {
+ fprintf(stdout, "%ld\n", num);
+ } else {
+ if (opt_long)
+ output_strlist (procs,num);
+ else
+ output_numlist (procs,num);
+ }
}
return !num; // exit(EXIT_SUCCESS) if match, otherwise exit(EXIT_FAILURE)
}