10

I imagine that kill -9 still just sends a signal to a process. If the process is not behaving well, I would imagine that kill -9 would have no effect. Indeed, today for the first time I saw kill -9 have no effect when sent to a stuck ruby process. So here is my question: Is there some harsher way to kill a process?

cat pants
  • 2,273
  • 10
  • 35
  • 46
  • You mention Ruby here, and I am curious what the pieces are that you are dealing with. I was using Webrick and had a similar experience, I started using `Rack::Server.new` and the processes were handled correctly, and would thereafter respond to `control-c`. – vgoff Dec 15 '12 at 01:01
  • vgoff, I will have to collect more information on the process. Let me get back to you on that. – cat pants Dec 16 '12 at 01:32

3 Answers3

15

You have to reboot the machine. If kill -9 doesn't kill a process, that means it is stuck in the kernel. Unless you can figure out what it's stuck on and unstick it, there's nothing you can do. The reason it's stuck is that it is waiting for something and the logic necessary to cleanly stop waiting simply doesn't exist.

(The above assumes the process has already been reparented to init. Otherwise, its parent may be keeping it around. You may have to kill its parent.)

David Schwartz
  • 31,449
  • 2
  • 55
  • 84
  • 1
    +1 like the answer. What I have found is it's often stuck on waiting for a parent that's already dead. A zombie won't take up memory, but it can fill up the process table if you have 1000s and occupy ports it's bound to. – aseq Dec 15 '12 at 00:16
  • A zombie process shouldn't be able to occupy ports. When the process terminates, all its file descriptors should be closed even before it's reaped. At least, that's what I'd always assumed. – David Schwartz Dec 15 '12 at 00:27
  • You may be right. I can't verify for certain, but at least it was (were) process(es) that couldn't be killed with kill -9 occupying a port. – aseq Dec 15 '12 at 02:21
  • FWIW, I had a stuck process that even had an open windows that wouldn’t close (frozen). SIGPWR didn’t help either, I had to reboot (Ubuntu 20.04 beta). – Torsten Bronger May 11 '20 at 14:12
10

Every time I have a job that is stuck and signals 9 or 15 won't kill it, I send it signal 30 (SIGPWR) and almost every single time it will clear it out. I can't recall when sending the power outage signal didn't work.

tpg2114
  • 201
  • 1
  • 3
3

Yes there is, a reboot...

Normally though being unable to kill -9 a process is not such a problem since these processes are not doing much to hog your system, they're probably just zombies. The only time it necessitated me to reboot in order to get rid of it is when it was "occupying" a tcp port I needed to use.

aseq
  • 4,610
  • 1
  • 24
  • 48