Unable to kill a python process

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Unable to kill a python process

Xiánwén Chén
Dear OpenBSD users,

I am not able to kill a python process.

$ pgrep python

showed a PID of 8926

However, I am not able to kill the process.

$ kill -9 8926

# kill -9 8926

Running as root did not help.

How can I kill this process?

Yours sincerely,
Xianwen

Reply | Threaded
Open this post in threaded view
|

Re: Unable to kill a python process

Maurice McCarthy-3
you could try kill -1 8926

Reply | Threaded
Open this post in threaded view
|

Re: Unable to kill a python process

Ingo Schwarze
In reply to this post by Xiánwén Chén
Hi,

Xianwen Chen wrote on Thu, Feb 13, 2020 at 08:10:17PM +0000:

> I am not able to kill a python process.
> $ pgrep python
> showed a PID of 8926
> However, I am not able to kill the process.
> $ kill -9 8926
> # kill -9 8926
> Running as root did not help.

Sounds like a zombie.  Seriously, i'm not joking.

> How can I kill this process?

You can't, a zombie is already dead.

Here is how i reproduced:

   $ sh
   $ echo $$
  39747
   $ python3
  Python 3.7.6 (default, Jan  1 2020, 13:51:25)
  [Clang 8.0.1 (tags/RELEASE_801/final)] on openbsd6
  Type "help", "copyright", "credits" or "license" for more information.
  >>>

Now, from a different terminal:

   $ kill -STOP 39747  # Block the reaper. (Seriously, i'm not joking.)
   $ pgrep python    
 61181
   $ kill 61181
   $ ps axu -p 61181
  USER       PID %CPU %MEM VSZ RSS TT STAT STARTED    TIME COMMAND
  schwarze 61181  0.0  0.0   0   0 pb Z    -       0:00.00 (python3.7)

The "STAT: Z" tells you it's a zombie.  It is already dead, but
still haunting the operating system.  You cannot kill(2) it; or
more precisely, killing it again won't make it any more dead than
it already is.

(Unless you pierce its heart with a woodden stick.  Sorry, now i was
joking.)

Just let the parent process reap it.  A well-behaved parent process
will do so by wait(2)ing for its children to die.  My earlier -STOP
signal prevented the parent shell from doing its job, so lets allow
that shell to get back to work:

   $ kill -CONT 39747
   $ ps axu -p 61181  
  USER       PID %CPU %MEM VSZ RSS TT STAT STARTED    TIME COMMAND
   $

So, now we got rid of the zombie by allowing the parent shell to
reap it.

If the parent process is ill-mannered and does not wait(2) on its
children, just kill the parent.  In that case, the parent deserves
the punishment.

Read the following manual page to understand why dying processes
don't vanish instantly but instead linger around until wait(2)ed
for by their parent:

  https://man.openbsd.org/wait.2

And see this manual page for what parents can do if they do not
need information about dying children:

  https://man.openbsd.org/sigaction.2#SA_NOCLDWAIT

Either way, don't create children if you aren't prepared to handle
the responsibility that comes with them - or you might end up being
haunted by zombies.

Yours,
  Ingo

Reply | Threaded
Open this post in threaded view
|

Re: Unable to kill a python process

Xiánwén Chén
In reply to this post by Maurice McCarthy-3
Dear Maurice,

> you could try kill -1 8926

Thank you. I just tried it. It did not kill the process.

Yours sincerely,
Xianwen

Reply | Threaded
Open this post in threaded view
|

Re: Unable to kill a python process

Ingo Schwarze
Hi,

Xianwen Chen wrote on Thu, Feb 13, 2020 at 09:31:45PM +0000:
> Maurice wrote:

>> you could try kill -1 8926

> Thank you. I just tried it. It did not kill the process.

Small wonder, you already already dropped a nuke on it (-9 = -KILL)
and even that didn't make the zombie go away.

You certainly can't kill a zombie by merely hanging up on it
on the phone (-1 = -HUP ;-).

Yours,
  Ingo

Reply | Threaded
Open this post in threaded view
|

Re: Unable to kill a python process

Xiánwén Chén
In reply to this post by Ingo Schwarze
Dear Ingo,

On 2/13/20, Ingo Schwarze <[hidden email]> wrote:
> (Unless you pierce its heart with a woodden stick.  Sorry, now i was
>    $ kill -CONT 39747

Thank you for showing me the wooden stick! It worked!

Yours sincerely,
Xianwen