summaryrefslogtreecommitdiff
path: root/usr.bin/pkill
diff options
context:
space:
mode:
authorlum <lum@cvs.openbsd.org>2012-01-17 04:27:21 +0000
committerlum <lum@cvs.openbsd.org>2012-01-17 04:27:21 +0000
commitd6faec294a86203398c9624e40a1fdea32b38643 (patch)
tree360c1ab1158fa77d06ef9b06d84b92e7f6c9e363 /usr.bin/pkill
parent0e2a5bf0a1ca86e32e322a89f22961d8468ec051 (diff)
Allow pkill to use the -l option. This displays which processes have been
signalled using the "Long" format, like pgrep. Original diff from FreeBSD, modified somewhat on tech@, with feedback from nicm@ Man page input from jmc@
Diffstat (limited to 'usr.bin/pkill')
-rw-r--r--usr.bin/pkill/pkill.113
-rw-r--r--usr.bin/pkill/pkill.c12
2 files changed, 14 insertions, 11 deletions
diff --git a/usr.bin/pkill/pkill.1 b/usr.bin/pkill/pkill.1
index 566f3a8c022..ec3bcd5be9f 100644
--- a/usr.bin/pkill/pkill.1
+++ b/usr.bin/pkill/pkill.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: pkill.1,v 1.16 2010/09/29 07:44:56 jmc Exp $
+.\" $OpenBSD: pkill.1,v 1.17 2012/01/17 04:27:20 lum 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: September 29 2010 $
+.Dd $Mdocdate: January 17 2012 $
.Dt PKILL 1
.Os
.Sh NAME
@@ -48,7 +48,7 @@
.Op Ar pattern ...
.Nm pkill
.Op Fl Ar signal
-.Op Fl fnovx
+.Op Fl flnovx
.Op Fl G Ar gid
.Op Fl g Ar pgrp
.Op Fl P Ar ppid
@@ -99,10 +99,9 @@ Print the process name in addition to the process ID for each matching
process.
If used in conjunction with
.Fl f ,
-print the process ID and the full argument list for each matching process.
-This option can only be used with the
-.Nm pgrep
-command.
+print the process ID and the full argument list for each matching process
+.Pf ( Nm pgrep
+only).
.It Fl n
Match only the most recently created (newest) process, if any.
Cannot be used in conjunction with
diff --git a/usr.bin/pkill/pkill.c b/usr.bin/pkill/pkill.c
index cfab3c7c211..89f67223eff 100644
--- a/usr.bin/pkill/pkill.c
+++ b/usr.bin/pkill/pkill.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pkill.c,v 1.19 2011/04/10 03:20:59 guenther Exp $ */
+/* $OpenBSD: pkill.c,v 1.20 2012/01/17 04:27:20 lum Exp $ */
/* $NetBSD: pkill.c,v 1.5 2002/10/27 11:49:34 kleink Exp $ */
/*-
@@ -112,6 +112,7 @@ main(int argc, char **argv)
char buf[_POSIX2_LINE_MAX], *mstr, **pargv, *p, *q;
int i, j, ch, bestidx, rv, criteria;
int (*action)(struct kinfo_proc *, int);
+ int did_action;
struct kinfo_proc *kp;
struct list *li;
u_int32_t bestsec, bestusec;
@@ -176,8 +177,6 @@ main(int argc, char **argv)
criteria = 1;
break;
case 'l':
- if (!pgrep)
- usage();
longfmt = 1;
break;
case 'n':
@@ -392,11 +391,16 @@ main(int argc, char **argv)
/*
* Take the appropriate action for each matched process, if any.
*/
+ did_action = 0;
rv = STATUS_NOMATCH;
for (i = 0, j = 0, kp = plist; i < nproc; i++, kp++) {
if ((kp->p_flag & P_SYSTEM) != 0 || kp->p_pid == mypid)
continue;
if (selected[i]) {
+ if (longfmt && !pgrep) {
+ did_action = 1;
+ printf("%d %s\n", (int)kp->p_pid, kp->p_comm);
+ }
if (inverse)
continue;
} else if (!inverse)
@@ -421,7 +425,7 @@ usage(void)
if (pgrep)
ustr = "[-flnovx] [-d delim]";
else
- ustr = "[-signal] [-fnovx]";
+ ustr = "[-signal] [-flnovx]";
fprintf(stderr, "usage: %s %s [-G gid] [-g pgrp] [-P ppid] [-s sid] "
"[-t tty]\n\t[-U uid] [-u euid] [pattern ...]\n", __progname, ustr);