summaryrefslogtreecommitdiff
path: root/usr.bin/pkill
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2012-08-21 06:28:37 +0000
committerMarc Espie <espie@cvs.openbsd.org>2012-08-21 06:28:37 +0000
commit2741430f011680555292e8d800c74d76a77cb36f (patch)
tree1665d7c6711f5f27c7830a18e9ea52bddf277e10 /usr.bin/pkill
parent95407281b9dcde137a20cbe29f1aedd6fd18a31a (diff)
add -q "silent" option similar to grep
okay ajacoutot@, guenther@
Diffstat (limited to 'usr.bin/pkill')
-rw-r--r--usr.bin/pkill/pkill.115
-rw-r--r--usr.bin/pkill/pkill.c14
2 files changed, 21 insertions, 8 deletions
diff --git a/usr.bin/pkill/pkill.1 b/usr.bin/pkill/pkill.1
index 83f5c95e717..90b9b5b9b82 100644
--- a/usr.bin/pkill/pkill.1
+++ b/usr.bin/pkill/pkill.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: pkill.1,v 1.18 2012/02/09 20:04:35 markus Exp $
+.\" $OpenBSD: pkill.1,v 1.19 2012/08/21 06:28:36 espie Exp $
.\" $NetBSD: pkill.1,v 1.8 2003/02/14 15:59:18 grant Exp $
.\"
.\" Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -28,7 +28,7 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd $Mdocdate: February 9 2012 $
+.Dd $Mdocdate: August 21 2012 $
.Dt PKILL 1
.Os
.Sh NAME
@@ -36,7 +36,7 @@
.Nd find or signal processes by name
.Sh SYNOPSIS
.Nm pgrep
-.Op Fl flnovx
+.Op Fl flnoqvx
.Op Fl d Ar delim
.Op Fl G Ar gid
.Op Fl g Ar pgrp
@@ -49,7 +49,7 @@
.Op Ar pattern ...
.Nm pkill
.Op Fl Ar signal
-.Op Fl flnovx
+.Op Fl flnoqvx
.Op Fl G Ar gid
.Op Fl g Ar pgrp
.Op Fl P Ar ppid
@@ -151,6 +151,13 @@ comma-separated list
.It Fl v
Reverse the sense of the matching;
display or signal processes that do not match the given criteria.
+.It Fl q
+Quiet mode.
+Perform the action, but don't display anything on standard output.
+Note that
+.Fl q
+takes precedence over other display options such as
+.Fl l .
.It Fl x
Require an exact match of the process name, or argument list if
.Fl f
diff --git a/usr.bin/pkill/pkill.c b/usr.bin/pkill/pkill.c
index d7c16eddac1..e97026deecb 100644
--- a/usr.bin/pkill/pkill.c
+++ b/usr.bin/pkill/pkill.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pkill.c,v 1.28 2012/07/10 12:48:08 halex Exp $ */
+/* $OpenBSD: pkill.c,v 1.29 2012/08/21 06:28:36 espie Exp $ */
/* $NetBSD: pkill.c,v 1.5 2002/10/27 11:49:34 kleink Exp $ */
/*-
@@ -83,6 +83,7 @@ int pgrep;
int signum = SIGTERM;
int newest;
int oldest;
+int quiet;
int inverse;
int longfmt;
int matchargs;
@@ -152,7 +153,7 @@ main(int argc, char **argv)
criteria = 0;
- while ((ch = getopt(argc, argv, "G:P:T:U:d:fg:lnos:t:u:vx")) != -1)
+ while ((ch = getopt(argc, argv, "G:P:T:U:d:fg:lnoqs:t:u:vx")) != -1)
switch (ch) {
case 'G':
makelist(&rgidlist, LT_GROUP, optarg);
@@ -193,6 +194,9 @@ main(int argc, char **argv)
oldest = 1;
criteria = 1;
break;
+ case 'q':
+ quiet = 1;
+ break;
case 's':
makelist(&sidlist, LT_SID, optarg);
criteria = 1;
@@ -420,7 +424,7 @@ main(int argc, char **argv)
else if (rv != STATUS_ERROR)
rv = STATUS_MATCH;
}
- if (pgrep && j)
+ if (pgrep && j && !quiet)
putchar('\n');
exit(rv);
@@ -446,7 +450,7 @@ usage(void)
int
killact(struct kinfo_proc *kp, int dummy)
{
- if (longfmt)
+ if (longfmt && !quiet)
printf("%d %s\n", (int)kp->p_pid, kp->p_comm);
if (kill(kp->p_pid, signum) == -1 && errno != ESRCH) {
@@ -461,6 +465,8 @@ grepact(struct kinfo_proc *kp, int printdelim)
{
char **argv;
+ if (quiet)
+ return (0);
if (printdelim)
fputs(delim, stdout);
if (longfmt && matchargs) {