Skip to content
  • Craig Small's avatar
    pkill: Return 0 if successfully killed process · 625d0809
    Craig Small authored
    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: default avatarCraig Small <csmall@enc.com.au>
    625d0809