Module Name:    src
Committed By:   simonb
Date:           Sat Oct 29 08:17:16 UTC 2022

Modified Files:
        src/usr.bin/pkill: pkill.1 pkill.c

Log Message:
Add a -q option for pgrep to not print anything; similar to grep -q.


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/usr.bin/pkill/pkill.1
cvs rdiff -u -r1.32 -r1.33 src/usr.bin/pkill/pkill.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/pkill/pkill.1
diff -u src/usr.bin/pkill/pkill.1:1.31 src/usr.bin/pkill/pkill.1:1.32
--- src/usr.bin/pkill/pkill.1:1.31	Sat Jan  1 08:34:35 2022
+++ src/usr.bin/pkill/pkill.1	Sat Oct 29 08:17:16 2022
@@ -1,4 +1,4 @@
-.\"	$NetBSD: pkill.1,v 1.31 2022/01/01 08:34:35 msaitoh Exp $
+.\"	$NetBSD: pkill.1,v 1.32 2022/10/29 08:17:16 simonb Exp $
 .\"
 .\" Copyright (c) 2002 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -27,7 +27,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd December 3, 2018
+.Dd October 29, 2022
 .Dt PKILL 1
 .Os
 .Sh NAME
@@ -37,7 +37,7 @@
 .Nd find or signal processes by name
 .Sh SYNOPSIS
 .Nm pgrep
-.Op Fl filnvx
+.Op Fl filnqvx
 .Op Fl d Ar delim
 .Op Fl G Ar gid
 .Op Fl g Ar pgrp
@@ -179,6 +179,13 @@ This option is valid only when given as 
 .Nm pkill .
 .El
 .Pp
+The following option is also available for
+.Nm pgrep :
+.Bl -tag -width xxxxxxxx
+.It Fl q
+Quiet; do not write anything to standard output.
+.El
+.Pp
 The
 .Fl l
 flag is also available for

Index: src/usr.bin/pkill/pkill.c
diff -u src/usr.bin/pkill/pkill.c:1.32 src/usr.bin/pkill/pkill.c:1.33
--- src/usr.bin/pkill/pkill.c:1.32	Sat Jul  2 20:50:26 2022
+++ src/usr.bin/pkill/pkill.c	Sat Oct 29 08:17:16 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: pkill.c,v 1.32 2022/07/02 20:50:26 ad Exp $	*/
+/*	$NetBSD: pkill.c,v 1.33 2022/10/29 08:17:16 simonb Exp $	*/
 
 /*-
  * Copyright (c) 2002, 2022 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: pkill.c,v 1.32 2022/07/02 20:50:26 ad Exp $");
+__RCSID("$NetBSD: pkill.c,v 1.33 2022/10/29 08:17:16 simonb Exp $");
 #endif /* !lint */
 
 #include <sys/types.h>
@@ -87,6 +87,7 @@ static int	prenice;
 static int	signum = SIGTERM;
 static int	nicenum;
 static int	newest;
+static int	quiet;
 static int	inverse;
 static int	longfmt;
 static int	matchargs;
@@ -181,7 +182,7 @@ main(int argc, char **argv)
 		} else
 			usage();
 	} else {
-		while ((ch = getopt(argc, argv, "G:P:U:d:fg:ilns:t:u:vx")) != -1)
+		while ((ch = getopt(argc, argv, "G:P:U:d:fg:ilnqs:t:u:vx")) != -1)
 			switch (ch) {
 			case 'G':
 				makelist(&rgidlist, LT_GROUP, optarg);
@@ -217,6 +218,11 @@ main(int argc, char **argv)
 				newest = 1;
 				criteria = 1;
 				break;
+			case 'q':
+				if (!pgrep)
+					usage();
+				quiet = 1;
+				break;
 			case 's':
 				makelist(&sidlist, LT_SID, optarg);
 				criteria = 1;
@@ -443,7 +449,7 @@ usage(void)
 		    getprogname());
 	else {
 		if (pgrep)
-			ustr = "[-filnvx] [-d delim]";
+			ustr = "[-filnqvx] [-d delim]";
 		else
 			ustr = "[-signal] [-filnvx]";
 
@@ -514,6 +520,9 @@ grepact(const struct kinfo_proc2 *kp)
 {
 	char **argv;
 
+	if (quiet)
+		return 1;
+
 	if (longfmt && matchargs) {
 
 		/*

Reply via email to