On 16 January 2012 at 07:43 Nicholas Marriott <[email protected]>
wrote:
> On Mon, Jan 16, 2012 at 04:50:32AM +0000, Mark Lumsden wrote:
> > On 15 January 2012 at 19:02 Nicholas Marriott <[email protected]>
> > wrote:
> >
> > > Hi
> > >
> > > I think that error message is misleading if you are running pkill as
> > > root.
> > >
> >
> > Yes, I agree.
> >
> > > How about instead of only printing if it did nothing, -l makes it always
> > > print "%d processes signalled"?
> >
> > Currently, the diff from Freebsd prints a line for each process that
> > is signalled:
> >
> > # pkill -l top
> > kill -15 20908
> > kill -15 9439
> >
> > I like the fact you can see which pids were affected.
>
> I think I'd like it more if it printed the -l output in the same format
> as pgrep, rather than pretending it is running kill(1), but it isn't too
> important.
>
Now, both pgrep and pkill are the same, I think I prefer it.
# pgrep -l p
20908 top
9439 pflogd
3577 pflogd
# pkill -l p
20908 top
9439 pflogd
3577 pflogd
> >
> > If none are affected, I can change the message to:
> >
> > "No matching processes were found."
>
> Actually, I don't see a need for a "no processes" message at all, surely
> just no "kill 1234" output is enough to mean nothing? pgrep doesn't print
> anything when it finds nothing.
>
I've taken this out. I agree with you.
> >
> > mark
I've amended the man page to reflect these changes...
mark
Index: pkill.1
===================================================================
RCS file: /cvs/src/usr.bin/pkill/pkill.1,v
retrieving revision 1.16
diff -u -p -r1.16 pkill.1
--- pkill.1 29 Sep 2010 07:44:56 -0000 1.16
+++ pkill.1 16 Jan 2012 08:16:33 -0000
@@ -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
@@ -97,12 +97,11 @@ command.
Long output.
Print the process name in addition to the process ID for each matching
process.
-If used in conjunction with
+For
+.Nm pgrep ,
+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.
.It Fl n
Match only the most recently created (newest) process, if any.
Cannot be used in conjunction with
Index: pkill.c
===================================================================
RCS file: /cvs/src/usr.bin/pkill/pkill.c,v
retrieving revision 1.19
diff -u -p -r1.19 pkill.c
--- pkill.c 10 Apr 2011 03:20:59 -0000 1.19
+++ pkill.c 16 Jan 2012 08:16:33 -0000
@@ -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);