LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 04-16-2012, 08:26 PM   #1
browny_amiga
Member
 
Registered: Dec 2001
Location: /mnt/UNV/Mlkway/Earth/USA/California/Silicon Valley
Distribution: Kubuntu, Debian Buster Stable, Windoze 7
Posts: 684

Rep: Reputation: 56
Smile 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
 
Old 04-16-2012, 09:12 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,348

Rep: Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749
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.
 
Old 04-17-2012, 08:57 AM   #3
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,610
Blog Entries: 4

Rep: Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905
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." 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.

Last edited by sundialsvcs; 04-17-2012 at 08:58 AM.
 
Old 04-17-2012, 01:24 PM   #4
browny_amiga
Member
 
Registered: Dec 2001
Location: /mnt/UNV/Mlkway/Earth/USA/California/Silicon Valley
Distribution: Kubuntu, Debian Buster Stable, Windoze 7
Posts: 684

Original Poster
Rep: Reputation: 56
Quote:
Originally Posted by sundialsvcs View Post
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." 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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Under what circumstances will a SIGKILL signal occur? rainman1985_2010 Programming 3 10-27-2011 10:19 PM
Can strace record which pid sent a SIGKILL/SIGTERM to a another process? jmcmillan Linux - General 0 06-17-2009 09:46 AM
Way to prevent SIGKILL J::2 Programming 5 03-26-2009 02:04 AM
Parents PID and SIGKILL psernaalvarez Programming 3 02-01-2008 06:20 PM
Sigkill suhanduman Linux - Enterprise 2 12-05-2007 05:08 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 01:04 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration