summaryrefslogtreecommitdiffstats
path: root/bin/pkill
diff options
context:
space:
mode:
authorpjd <pjd@FreeBSD.org>2010-02-12 18:52:24 +0000
committerpjd <pjd@FreeBSD.org>2010-02-12 18:52:24 +0000
commitb7ae6c55592057f4c5666982f689bf29094fe780 (patch)
tree2db3e83a83838cfe63cb466ccc99bc561510f5b1 /bin/pkill
parent31c6160ef9b4c453564cf7797a45f4a8bd210c77 (diff)
downloadFreeBSD-src-b7ae6c55592057f4c5666982f689bf29094fe780.zip
FreeBSD-src-b7ae6c55592057f4c5666982f689bf29094fe780.tar.gz
- Implement -q option for pgrep(1).
- Add regression test to test -q option.
Diffstat (limited to 'bin/pkill')
-rw-r--r--bin/pkill/pkill.16
-rw-r--r--bin/pkill/pkill.c19
2 files changed, 20 insertions, 5 deletions
diff --git a/bin/pkill/pkill.1 b/bin/pkill/pkill.1
index 1db38f0..5eec10f 100644
--- a/bin/pkill/pkill.1
+++ b/bin/pkill/pkill.1
@@ -36,7 +36,7 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd May 16, 2009
+.Dd February 11, 2010
.Dt PKILL 1
.Os
.Sh NAME
@@ -44,7 +44,7 @@
.Nd find or signal processes by name
.Sh SYNOPSIS
.Nm pgrep
-.Op Fl LSafilnovx
+.Op Fl LSafilnoqvx
.Op Fl F Ar pidfile
.Op Fl G Ar gid
.Op Fl M Ar core
@@ -175,6 +175,8 @@ command.
Select only the newest (most recently started) of the matching processes.
.It Fl o
Select only the oldest (least recently started) of the matching processes.
+.It Fl q
+Do not write anything to standard output.
.It Fl s Ar sid
Restrict matches to processes with a session ID in the comma-separated
list
diff --git a/bin/pkill/pkill.c b/bin/pkill/pkill.c
index 153c90f..a2d5f47 100644
--- a/bin/pkill/pkill.c
+++ b/bin/pkill/pkill.c
@@ -49,6 +49,7 @@ __FBSDID("$FreeBSD$");
#include <sys/time.h>
#include <sys/user.h>
+#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
@@ -110,6 +111,7 @@ static int matchargs;
static int fullmatch;
static int kthreads;
static int cflags = REG_EXTENDED;
+static int quiet;
static kvm_t *kd;
static pid_t mypid;
@@ -180,10 +182,11 @@ main(int argc, char **argv)
debug_opt = 0;
pidfile = NULL;
pidfilelock = 0;
+ quiet = 0;
execf = NULL;
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:ij:lnoqs:t:u:vx")) != -1)
switch (ch) {
case 'D':
debug_opt++;
@@ -258,6 +261,11 @@ main(int argc, char **argv)
oldest = 1;
criteria = 1;
break;
+ case 'q':
+ if (!pgrep)
+ usage();
+ quiet = 1;
+ break;
case 's':
makelist(&sidlist, LT_SID, optarg);
criteria = 1;
@@ -549,7 +557,7 @@ usage(void)
const char *ustr;
if (pgrep)
- ustr = "[-LSfilnovx] [-d delim]";
+ ustr = "[-LSfilnoqvx] [-d delim]";
else
ustr = "[-signal] [-ILfinovx]";
@@ -567,6 +575,10 @@ show_process(const struct kinfo_proc *kp)
{
char **argv;
+ if (quiet) {
+ assert(pgrep);
+ return;
+ }
if ((longfmt || !pgrep) && matchargs &&
(argv = kvm_getargv(kd, kp, 0)) != NULL) {
printf("%d ", (int)kp->ki_pid);
@@ -623,7 +635,8 @@ grepact(const struct kinfo_proc *kp)
{
show_process(kp);
- printf("%s", delim);
+ if (!quiet)
+ printf("%s", delim);
return (1);
}
OpenPOWER on IntegriCloud