Linux - GeneralThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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).
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.