diff options
author | Craig Small <csmall@enc.com.au> | 2017-02-04 11:44:01 +1100 |
---|---|---|
committer | Craig Small <csmall@enc.com.au> | 2017-02-04 12:00:24 +1100 |
commit | ff05573f0ddbf7f5cf9f3c81b9c183ff05494ab1 (patch) | |
tree | 7f720475e2633002d2ad1d409751530ab9c4dbc2 /pgrep.1 | |
parent | 1f094f51f176aae365845cb06a53cade662b52de (diff) | |
download | procps-ng-ff05573f0ddbf7f5cf9f3c81b9c183ff05494ab1.tar.gz |
pkill: Return 0 if successfully killed process
Original report:
When trying kill a process with insufficient privileges (see blow),
pkill displays the error message “... failed: Operation not permitted”,
but returns 0. Surely it should return 3?
$ pkill syslogd ; echo $?
pkill: killing pid 373 failed: Operation not permitted
0
Return value 0 means one of more things matched. For a pgrep (which
shares code with pkill) this makes sense, there was a match. It seems
wrong for pkill to return 0 when it in fact could not do what you told
it to. However return value 3 means a fatal error and it's not fatal.
Looking at other programs when trying to kill things it cannot kill.
shell kill returns 1, procps kill returns 1, killall returns 1, skill
returns 0 (and says it was successful!, ah well poor old skill)
The consensus seems to be that you return 1 if you cannot kill it, even
if you found it. In other words the return value for both not found and
not able to kill it is the same.
pkill only returns 0 if something was killed. This means we found a
match AND the kill() system call worked too.
References:
https://bugs.debian.org/852758
Signed-off-by: Craig Small <csmall@enc.com.au>
Diffstat (limited to 'pgrep.1')
-rw-r--r-- | pgrep.1 | 16 |
1 files changed, 11 insertions, 5 deletions
@@ -1,8 +1,13 @@ -.\" Manual page for pgrep / pkill. -.\" Licensed under version 2 of the GNU General Public License. +.\" .\" Copyright 2000 Kjetil Torgrim Homme +.\" 2017 Craig Small +.\" +.\" This program is free software; you can redistribute it and/or modify +.\" it under the terms of the GNU General Public License as published by +.\" the Free Software Foundation; either version 2 of the License, or +.\" (at your option) any later version. .\" -.TH PGREP "1" "September 2015" "procps-ng" "User Commands" +.TH PGREP "1" "2017-02-04" "procps-ng" "User Commands" .SH NAME pgrep, pkill \- look up or signal processes based on name and other attributes .SH SYNOPSIS @@ -197,10 +202,11 @@ $ renice +4 $(pgrep netscape) .PD 0 .TP 0 -One or more processes matched the criteria. +One or more processes matched the criteria. For pkill the process must also +have been successfully signalled. .TP 1 -No processes matched. +No processes matched or none of them could be signalled. .TP 2 Syntax error in the command line. |