CVS commit: src/usr.bin/pkill
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 +.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 #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 @@ -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(, 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(, 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) { /*
CVS commit: src/usr.bin/pkill
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.
CVS commit: src/usr.bin/pkill
Module Name:src Committed By: ad Date: Sat Jul 2 20:50:26 UTC 2022 Modified Files: src/usr.bin/pkill: pkill.c Log Message: Cosmetic tweak. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.31 -r1.32 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.c diff -u src/usr.bin/pkill/pkill.c:1.31 src/usr.bin/pkill/pkill.c:1.32 --- src/usr.bin/pkill/pkill.c:1.31 Tue Feb 21 13:09:56 2017 +++ src/usr.bin/pkill/pkill.c Sat Jul 2 20:50:26 2022 @@ -1,7 +1,7 @@ -/* $NetBSD: pkill.c,v 1.31 2017/02/21 13:09:56 kre Exp $ */ +/* $NetBSD: pkill.c,v 1.32 2022/07/02 20:50:26 ad Exp $ */ /*- - * Copyright (c) 2002 The NetBSD Foundation, Inc. + * Copyright (c) 2002, 2022 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation @@ -31,7 +31,7 @@ #include #ifndef lint -__RCSID("$NetBSD: pkill.c,v 1.31 2017/02/21 13:09:56 kre Exp $"); +__RCSID("$NetBSD: pkill.c,v 1.32 2022/07/02 20:50:26 ad Exp $"); #endif /* !lint */ #include @@ -266,7 +266,7 @@ main(int argc, char **argv) * Allocate memory which will be used to keep track of the * selection. */ - if ((selected = calloc((size_t)1, (size_t)nproc)) == NULL) + if ((selected = calloc(sizeof(*selected), (size_t)nproc)) == NULL) err(STATUS_ERROR, "Cannot allocate memory for %d processes", nproc);
CVS commit: src/usr.bin/pkill
Module Name:src Committed By: ad Date: Sat Jul 2 20:50:26 UTC 2022 Modified Files: src/usr.bin/pkill: pkill.c Log Message: Cosmetic tweak. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.31 -r1.32 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.
re: CVS commit: src/usr.bin/pkill
| this seems like a fairly big semantic change to me. | | could you change it to take a new option to look in argv[0] instead | of p_comm? p_comm is not changeable by the user. You could already do this with -f. The point was to make the default case behave intuitively. Adding an option is against that. I could add backwards compatibility by checking both, but I think that in the long term this will be dangerous and confusing (since you might end up killing more than you thought you would...) but again, it's a semantic change. the old system was a constant identifier that never changed over the life of the process (it may not be unique.) the argument list is under the control of the process itself, so what's being matched here is a different thing. i guess i've known about the 16-byte limitation and understood it, but since it was p_comm it was a reasonable limit. now there is no way to match against p_comm at all, right? .mrg.
Re: CVS commit: src/usr.bin/pkill
In article 20121121080326.gl...@snowdrop.l8s.co.uk, David Laight da...@l8s.co.uk wrote: On Tue, Nov 20, 2012 at 05:52:02PM -0500, Christos Zoulas wrote: Module Name: src Committed By:christos Date:Tue Nov 20 22:52:02 UTC 2012 Modified Files: src/usr.bin/pkill: pkill.c Log Message: Don't use p_comm since it is only 16 characters long and you can find the full argv[0]. It is just confusing to have a long command name, that ps shows as the long command name, and then when you try to kill it using the full command name as displayed you don't get a match. While there fix a format nit, and remove the main() declaration. This might break some scripts. Well, I could put backwards compatibility, but it is more dangerous to do so in the long term. Kids: don't use pkill(1) in scripts. christos
re: CVS commit: src/usr.bin/pkill
In article 20121121080326.gl...@snowdrop.l8s.co.uk, David Laight da...@l8s.co.uk wrote: On Tue, Nov 20, 2012 at 05:52:02PM -0500, Christos Zoulas wrote: Module Name: src Committed By: christos Date: Tue Nov 20 22:52:02 UTC 2012 Modified Files: src/usr.bin/pkill: pkill.c Log Message: Don't use p_comm since it is only 16 characters long and you can find the full argv[0]. It is just confusing to have a long command name, that ps shows as the long command name, and then when you try to kill it using the full command name as displayed you don't get a match. While there fix a format nit, and remove the main() declaration. This might break some scripts. Well, I could put backwards compatibility, but it is more dangerous to do so in the long term. Kids: don't use pkill(1) in scripts. this seems like a fairly big semantic change to me. could you change it to take a new option to look in argv[0] instead of p_comm? p_comm is not changeable by the user. .mrg.
re: CVS commit: src/usr.bin/pkill
On Nov 22, 4:39am, m...@eterna.com.au (matthew green) wrote: -- Subject: re: CVS commit: src/usr.bin/pkill | this seems like a fairly big semantic change to me. | | could you change it to take a new option to look in argv[0] instead | of p_comm? p_comm is not changeable by the user. You could already do this with -f. The point was to make the default case behave intuitively. Adding an option is against that. I could add backwards compatibility by checking both, but I think that in the long term this will be dangerous and confusing (since you might end up killing more than you thought you would...) christos
Re: CVS commit: src/usr.bin/pkill
On Wed, Nov 21, 2012 at 12:43:20PM -0500, Christos Zoulas wrote: On Nov 22, 4:39am, m...@eterna.com.au (matthew green) wrote: -- Subject: re: CVS commit: src/usr.bin/pkill | this seems like a fairly big semantic change to me. | | could you change it to take a new option to look in argv[0] instead | of p_comm? p_comm is not changeable by the user. You could already do this with -f. The point was to make the default case behave intuitively. Adding an option is against that. I could add backwards compatibility by checking both, but I think that in the long term this will be dangerous and confusing (since you might end up killing more than you thought you would...) That (killing too much) is always true when you use something like pkill(). At least it is better that the 'ps | grep' I've seen many people do! Is pkill() guaranteed to do an atomic traversal of the process list? So it will kill something that keeps using fork() to change its pid. David -- David Laight: da...@l8s.co.uk
Re: CVS commit: src/usr.bin/pkill
In article 20121121200309.gn...@snowdrop.l8s.co.uk, David Laight da...@l8s.co.uk wrote: On Wed, Nov 21, 2012 at 12:43:20PM -0500, Christos Zoulas wrote: On Nov 22, 4:39am, m...@eterna.com.au (matthew green) wrote: -- Subject: re: CVS commit: src/usr.bin/pkill | this seems like a fairly big semantic change to me. | | could you change it to take a new option to look in argv[0] instead | of p_comm? p_comm is not changeable by the user. You could already do this with -f. The point was to make the default case behave intuitively. Adding an option is against that. I could add backwards compatibility by checking both, but I think that in the long term this will be dangerous and confusing (since you might end up killing more than you thought you would...) That (killing too much) is always true when you use something like pkill(). At least it is better that the 'ps | grep' I've seen many people do! Yes, this is why it is best to not use things that kill by name from scripts. Is pkill() guaranteed to do an atomic traversal of the process list? So it will kill something that keeps using fork() to change its pid. I don't think our libkvm offers that. christos
Re: CVS commit: src/usr.bin/pkill
On Wed, Nov 21, 2012 at 01:36:01PM -0700, Warner Losh wrote: Is pkill() guaranteed to do an atomic traversal of the process list? So it will kill something that keeps using fork() to change its pid. I don't think our libkvm offers that. How could you guarantee this short of moving this into the kernel so you could do all the comparisons while keeping all forks from happening? You probably can't ... Even in the kernel it might be 'interesting'. David -- David Laight: da...@l8s.co.uk
Re: CVS commit: src/usr.bin/pkill
On Nov 21, 2012, at 1:55 PM, David Laight wrote: On Wed, Nov 21, 2012 at 01:36:01PM -0700, Warner Losh wrote: Is pkill() guaranteed to do an atomic traversal of the process list? So it will kill something that keeps using fork() to change its pid. I don't think our libkvm offers that. How could you guarantee this short of moving this into the kernel so you could do all the comparisons while keeping all forks from happening? You probably can't ... Even in the kernel it might be 'interesting'. Agreed. It was a leading question. Even with help from the kernel, it would be difficult Warner
Re: CVS commit: src/usr.bin/pkill
On Tue, Nov 20, 2012 at 05:52:02PM -0500, Christos Zoulas wrote: Module Name: src Committed By: christos Date: Tue Nov 20 22:52:02 UTC 2012 Modified Files: src/usr.bin/pkill: pkill.c Log Message: Don't use p_comm since it is only 16 characters long and you can find the full argv[0]. It is just confusing to have a long command name, that ps shows as the long command name, and then when you try to kill it using the full command name as displayed you don't get a match. While there fix a format nit, and remove the main() declaration. This might break some scripts. David -- David Laight: da...@l8s.co.uk
Re: CVS commit: src/usr.bin/pkill
cvs rdiff -u -r1.25 -r1.26 src/usr.bin/pkill/pkill.c Looks like -l option is necessary for prenice also. enami.