LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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 11-18-2009, 02:02 PM   #1
genmaicha
Member
 
Registered: Apr 2009
Posts: 38

Rep: Reputation: 15
proper way to kill unix daemons?


In general, is it safe to assume that a properly written unix daemon will gracefully exit upon receiving a SIGTERM signal? (The default signal for the kill command). Or do major unix daemon programs not follow this?

For example, the ISC-dhcpd man page says clearly that SIGTERM should be used to gracefully shutdown the server. But the sshd man page (say) does not say anything about graceful shutdown, so how am I supposed to know?

(I understand that on most distros you'd use sysV or BSD style scripts to control services-- this is more of a hypothetical question for when you had to compile a daemon not provided by your distro from scratch and it didn't come with scripts, or when you were putting together your own distros, etc).
 
Old 11-18-2009, 02:22 PM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
In "general" it is best to try progressive approach to killing things:

kill <process>
kill -1 <process>
kill -9 <process>

Some things don't die with a sigterm (e.g. shell sessions for some reason) but do with -1 (sighup). The -9 (sigkill) is always last resort as it tells the process to die without attempting any kind of graceful shutdown.

Also there are some things that it might not make sense to try killing at all. Items started by xinetd or inetd are going to be restarted on next request so if you want to prevent those daemons from relaunching you'd need to stop them in xinetd/inetd. Items started with "respawn" in /etc/inittab will restart automatically when they die (from a kill or some other reason) so you'd need to set them to "off" and run "init q" to reread the inittab to stop them. Other scenarios might be things you launch from cron or anacron periodically - you'd need to be sure you commented out or remove that cron/anacron entry.

Last edited by MensaWater; 11-18-2009 at 04:15 PM.
 
Old 11-18-2009, 02:31 PM   #3
rweaver
Senior Member
 
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833

Rep: Reputation: 167Reputation: 167
Generally a sig 15 (TERM) will cause the daemon to say 'I need to exit, write stuff out if necessary, and shutdown.' A sig 9 (KILL) will pretty much yank it out of memory very non-gracefully. Most unix daemons are setup to exit cleanly on a 15. Sig 1 (HUP) is a mixed bag, it used to restart a daemon cleanly... now... eh... behavior is variable... sometimes its a clean restart, sometimes a graceful restart (lets connections end before restarting), sometimes its a kill, sometimes its nothing at all.

Last edited by rweaver; 11-18-2009 at 02:34 PM.
 
  


Reply



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
What if 'kill -9' fails to kill a task? chii-chan Linux - Newbie 15 03-27-2013 03:47 PM
[SOLVED] Kill a hung task when kill -9 doesn't help 10110111 Linux - General 4 04-02-2009 11:10 AM
what is the powerfull kill command in UNIX just_a_kid Linux - Newbie 5 08-29-2007 01:02 PM
proper way to kill a non-responding app? bobbens Debian 10 10-21-2005 07:52 AM
how to use kill to kill a batch of processes with same name? dr_zayus69 Linux - Software 2 09-03-2005 06:35 PM

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

All times are GMT -5. The time now is 04:10 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