LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   first SIGTERM, then SIGKILL (https://www.linuxquestions.org/questions/linux-general-1/first-sigterm-then-sigkill-940132/)

browny_amiga 04-16-2012 08:26 PM

first SIGTERM, then SIGKILL
 
Hi,

I have come across A LOT of annoying and stubborn tasks in the last months that really just ignore SIGTERM and then still need to killed and forcefully removed by SIGKILL.

What I usually do is use SIGTERM twice. If it reports that no such task exists after the second time, it has worked properly (funny: showing an error means worked as it should).
Often though, it reports nothing, and is useless. So I still have to use a SIGKILL afterwards to get the job finally done.

Is there a command that does this already? First sends a nice one and checks if the process really got terminated and otherwise sends one that will work in any case?

Thanks,

Markus

chrism01 04-16-2012 09:12 PM

Easiest thing is to write a short script to do that, that takes the PID as a param.
You could even use an alias or create a bash fn to call it.

sundialsvcs 04-17-2012 08:57 AM

However... perhaps you are just being a little to hasty. If you want a process to terminate itself graciously (and you probably do), then you should send it a SIGTERM and then wait a reasonable amount of time for it to respond. There is no need to send the same signal twice.

SIGKILL is what a Dungeons & Dragons aficionado at my University referred to as "fodsnipor" = Finger Of Death, No Saving Throw, No Possibility of Resurrection." :eek: Or, as "Bones" McCoy would have put it (in the original and as far as I am concerned only Star Trek): "You're dead, Jim." The target is terminated, immediately and unconditionally and with no opportunity to defend itself or to clean up its mess. Probably not what you want to do, and if you find that you must, find out why.

browny_amiga 04-17-2012 01:24 PM

Quote:

Originally Posted by sundialsvcs (Post 4655075)
However... perhaps you are just being a little to hasty. If you want a process to terminate itself graciously (and you probably do), then you should send it a SIGTERM and then wait a reasonable amount of time for it to respond. There is no need to send the same signal twice.

SIGKILL is what a Dungeons & Dragons aficionado at my University referred to as "fodsnipor" = Finger Of Death, No Saving Throw, No Possibility of Resurrection." :eek: Or, as "Bones" McCoy would have put it (in the original and as far as I am concerned only Star Trek): "You're dead, Jim." The target is terminated, immediately and unconditionally and with no opportunity to defend itself or to clean up its mess. Probably not what you want to do, and if you find that you must, find out why.

Too bad there is no command, seems funny that I am the first one to come up with this requirement.
The programs and tools I am terminating don't need more than 1 second to clean up, the system is not that heavily loaded that it would take that long to clean up. And when they crash and get stuck, so that only a SIGKILL will help, they won't do any cleanup in any case. I have not so far experienced that a task that I sent a SIGTERM still came around and cleaned up, after I sent a SIGTERM twice, they hang in all cases and just refuse to go away.
I knew that this is possible to do with a script, but it is ugly to have to do this by hand and not use a standardized tool. Especially for such a basic no brain functionality that could be called "kill and make sure that task is really removed"

Cheers

Markus


All times are GMT -5. The time now is 02:13 AM.