Unable to kill process, even with root. How to diagnose?

7,158

Note that the "unkillable" bash processes are running as user p:

user    6174  0.0  0.0  13016    28 pts/19   Ss+  Feb13   0:04 /bin/bash
p        10964  0.0  0.0  11700    28 pts/2    Ss+  Feb11   0:01 bash 
p        11126  0.0  0.0   7952   560 pts/3    Ss+  Feb11   0:00 bash 
user   18195  0.0  0.0  17320   344 pts/9    Ss+  Apr22   0:29 /bin/bash

You're running as user user so you cannot just kill any processes of user p.

If you have sudo access, you could issue the kill commands either as root or as the p user. For things that might be old user sessions, using kill -HUP would be better than just kill, as it allows things like editors to save a backup of any unsaved work before exiting. Also, interactive shell processes (i.e. old sessions) can be immune to a regular kill, but kill -HUP works just fine for them.

To issue the kill command as user p:

user$ sudo -u p kill -HUP 10964 11126

or by using root power:

user$ sudo kill -HUP 10964 11126

For processes running as user p, a kill command issued as user p will be just as strong as a kill command issued by root: even regular users have complete power over the life and death of any process they own themselves.

Share:
7,158

Related videos on Youtube

user13107
Author by

user13107

Updated on September 18, 2022

Comments

  • user13107
    user13107 almost 2 years

    There are a lot of bash processes running on my Ubuntu Linux (12.04). Even when I close the terminal they are still shown in the System Monitor.

    I tried killing them as below, but they remain as it is. How to diagnose the issue, why can't they be terminated?

    user$ ps aux | grep bash
    user    2807  0.0  0.0   9484    56 pts/20   Ss+  Mar18   0:00 /bin/bash
    user    4431  0.0  0.1   9228  5616 pts/7    Ss   10:39   0:00 bash
    user    4655  0.0  0.0   4372   844 pts/7    R+   10:45   0:00 grep --color=auto --exclude-dir=.svn bash
    user    5664  0.0  0.0  12764    12 pts/6    Ss   Feb05   0:01 /bin/bash
    user    5812 99.6  0.1  11276  7088 ?        Rs   Sep22 3923:00 bash
    user    6174  0.0  0.0  13016    28 pts/19   Ss+  Feb13   0:04 /bin/bash
    p        10964  0.0  0.0  11700    28 pts/2    Ss+  Feb11   0:01 bash 
    p        11126  0.0  0.0   7952   560 pts/3    Ss+  Feb11   0:00 bash 
    user   18195  0.0  0.0  17320   344 pts/9    Ss+  Apr22   0:29 /bin/bash
    user   21721  0.0  0.0  15924     4 pts/10   Ss+  Feb01   0:10 /bin/bash
    user   22915  4.7  0.3  19400 13056 pts/22   Rs+  Jul29 3950:07 /bin/bash
    user   24030  0.0  0.0  13740     4 pts/23   Ss+  Mar24   0:15 /bin/bash
    user   29787  0.0  0.1   9220  5572 pts/11   Ss+  Sep23   0:00 /bin/bash
    user$ 
    user$ pkill -f bash
    pkill: 10964 - Operation not permitted
    pkill: 11126 - Operation not permitted
    user$ sudo pkill -f bash
    user$ 
    user$ ps aux | grep bash
    user    2807  0.0  0.0   9484    56 pts/20   Ss+  Mar18   0:00 /bin/bash
    user    4431  0.0  0.1   9228  5616 pts/7    Ss   10:39   0:00 bash
    user    4660  0.0  0.0   4372   844 pts/7    R+   10:45   0:00 grep --color=auto --exclude-dir=.svn bash
    user    5664  0.0  0.0  12764    12 pts/6    Ss   Feb05   0:01 /bin/bash
    user    5812 99.6  0.1  11276  7088 ?        Rs   Sep22 3923:21 bash
    user    6174  0.0  0.0  13016    28 pts/19   Ss+  Feb13   0:04 /bin/bash
    p        10964  0.0  0.0  11700    28 pts/2    Ss+  Feb11   0:01 bash 
    p        11126  0.0  0.0   7952   560 pts/3    Ss+  Feb11   0:00 bash 
    user   18195  0.0  0.0  17320   344 pts/9    Ss+  Apr22   0:29 /bin/bash
    user   21721  0.0  0.0  15924     4 pts/10   Ss+  Feb01   0:10 /bin/bash
    user   22915  4.7  0.3  19400 13056 pts/22   Rs+  Jul29 3950:29 /bin/bash
    user   24030  0.0  0.0  13740     4 pts/23   Ss+  Mar24   0:15 /bin/bash
    user   29787  0.0  0.1   9220  5572 pts/11   Ss+  Sep23   0:00 /bin/bash
    
    • Justin
      Justin almost 9 years
      What does kill 29787 do? What about kill -9 29787?
    • user13107
      user13107 almost 9 years
      @MatthiasDiener sorry, didn't see the comment earlier. I rebooted PC and now the problem is gone. I had tried killing by PID but it didn't work (i think it gave no output on terminal)
    • Anwar
      Anwar almost 9 years
      First you need to stop those bash processes then kill it. Also make sure you should either be the owner of the process or a privileged user to kill a process.
    • Surabhi
      Surabhi almost 9 years
      @user13107, No output in the terminal means that it worked. Even when pkill does not work, kill -9 should most definitely work when running as root.
    • Philip Couling
      Philip Couling about 5 years
      @peschke be careful. No output means it did not result in an error. Whether or not it worked is an entirely different matter.
    • endrias
      endrias over 4 years
      Have you tried killall bash ?
  • Kusalananda
    Kusalananda over 5 years
    I'm noticing that there is a bash process using 99.6% of a CPU in the output of ps in the question. This may be the one that they want to actually terminate. It doesn't terminate though (and no other bash process seems to die either). I've voted to close the Q as unreproducible/problem went away.