Live data from Hacker News

When should I not kill -9 a process?

unix.stackexchange.com

21–30 of 85 posts

Re: When should I not kill -9 a process?

#21
Don't exaggerate the impact of a kill -9. It can be safe if a homegrown application has a bug or there is a hardware failure preventing a clean reboot (like a locked IO to a disk that is no longer in order).

Sure it will mess up some things, but when management is pushing to limit the downtime of, for instance, a golden-image provisioned Linux machine, I'd kill it off no problem.

Now when we are talking a hardware box running some form of Oracle/mySQL - no, don't use -9 indeed.

Re: When should I not kill -9 a process?

#22
post #10
post #4

As if often the case with stackoverflow answers, all of them are wrong in different ways. You should only kill -9 when every other signal the program is likely to respond to has not worked. kill -9 is likely to leave program in a state that requires manual intervention, especially if that program is a database. If you're a developer, before you kill -9 a program send SIGTERM (ie kill without args or kill -15). If the…

You can't really corrupt a database that easily, can you? That's half the point of using a database, so you have transactions, etc.

I don't remember the exact details, but I once had a DB admin flabbergasted because there was a non-numeric character in a field/row that was numeric. The DB engine crashed upon starting and could not clean it up.

I think it was Oracle.

If I remember correctly we had to get the vendor involved

This happened after an unclean shutdown (power failure). The disk were RAID, but the cache battery was dead so there was some corrupt data written to the disk on block level.

THis could happen too on a kill -9.

Re: When should I not kill -9 a process?

#23
post #4

As if often the case with stackoverflow answers, all of them are wrong in different ways. You should only kill -9 when every other signal the program is likely to respond to has not worked. kill -9 is likely to leave program in a state that requires manual intervention, especially if that program is a database. If you're a developer, before you kill -9 a program send SIGTERM (ie kill without args or kill -15). If the…

As a useful variant of this: I have grown accustomed to killing processes that hang with kill -11 (SIGSEGV). This is essentially the same as -9, with the exception that it creates a coredump. Saves a lot of hassle with manually attaching GDB.

It's probably better to use SIGABRT (-6) for that, as it also dumps core and is less likely to be handled by the process (there are valid reasons to handle SIGSEGV and continue in execution)

Re: When should I not kill -9 a process?

#25
post #17
post #4

As if often the case with stackoverflow answers, all of them are wrong in different ways. You should only kill -9 when every other signal the program is likely to respond to has not worked. kill -9 is likely to leave program in a state that requires manual intervention, especially if that program is a database. If you're a developer, before you kill -9 a program send SIGTERM (ie kill without args or kill -15). If the…

If a database is not kill -9 resistant then how can it be power-off resistant?

Who says it was?

Re: When should I not kill -9 a process?

#26
post #18

Earlier quoted context omitted.

As a useful variant of this: I have grown accustomed to killing processes that hang with kill -11 (SIGSEGV). This is essentially the same as -9, with the exception that it creates a coredump. Saves a lot of hassle with manually attaching GDB.

Yup, there are risks too though with that approach. You should be sure that ulimit for core size is large enough (not default almost always). Also, a core dump can take a very long time if your programs address space is large. It might involve writing tens of gigabytes to disk. So not only do you need the file system space, but you also need to be prepared to wait tens of minutes while your program is dumping core.

While what you say is true, this is not really a problem in practice; most of the time, the process doesn't have the amount of memory allocated to be a serious problem, and the coredump file is written in a smart way [1]: usually, the address space has many 'gaps': instead of writing these all as \0 characters to disk, it uses more elaborate storage techniques. The end result is that you can have a coredump file which is reported to have a size of 1GB, while only having 100MB written on disk.

[1] https://en.wikipedia.org/wiki/Core_dump#Format

Re: When should I not kill -9 a process?

#27
post #2

Fiber optic cables are dug up by backhoes. Hard drives randomly fail. RAM is corrupted by cosmic rays. Racks lose power. CPU fans stop spinning. If your process relies on not being kill -9'd, then you might as well quit programming and go buy a lottery ticket.

Yes, your process shouldn't eat data on a kill -9. At the same time, in a lot of applications, kill -9 can make other things less convenient. If your app is in a cluster, that job you just kill -9'ed is now suddenly not sending out heartbeat messages, which means the servers around it are waiting, with data stacking up, wondering what happened to that process you just shot in the head. Yes, it'll recover when things come back up, but you've just added more work on the other servers. Or, that server task didn't write the last few log entries. Given you're killing jobs, those stragglers may have data as to why you needed to stop things in the first place. In short, you shouldn't kill -9 right away because well-written programs talk about their state to the programs and log files around it, and those last messages can be very useful in giving information as to what is happening with your program.

Re: When should I not kill -9 a process?

#28
post #8
post #2

Fiber optic cables are dug up by backhoes. Hard drives randomly fail. RAM is corrupted by cosmic rays. Racks lose power. CPU fans stop spinning. If your process relies on not being kill -9'd, then you might as well quit programming and go buy a lottery ticket.

This is a bit like saying that since your car can do emergency braking, you should always do emergency braking. Some processes clean up after themselves more neatly, or finish the current run of what they're doing first. It's dependent on what it is that you're stopping.

How is it anything like that?

Re: When should I not kill -9 a process?

#30
We write all of our server code with kill -9 in mind. Basically, eveything we have can be killed with -9 without any problems. It needs some cleanup code for lefover files or things like that. And use of atomic operations here and there.. But then you are ready for all kinds of hardware issues.
Post reply on HN