I have heard that "shutdown -h now" is not a graceful shut down command because it does something akin to "kill -9" for all processes, as opposed to "kill -15".

Is this true, and if so, what is a more graceful way of shutting down to ensure everything has time to clean up after its self?

P.s. Using CentOS, Ubuntu, and Debian mainly.

  • I'll wait for someone else to chime in, but that doesn't sound right at all. -h is just telling it to place the system into HALT mode as opposed to reboot. And "now" just means there's no grace period for users to shutdown. Not sure how any of these would modify the actual kill behavior of shutdown – Jeffery Smith Nov 4 '11 at 12:03
  • 4
    Please read the manual page for shutdown (man shutdown). It explains this completely. – Andrew Schulman Nov 4 '11 at 12:07

shutdown -h now will call /etc/rc.d/rc or /etc/init.d/rc. The rc script will call the kill scripts for the new runlevel (0 for -h, 6 for -r), followed by any start scripts.

You'll see S30killprocs or S00killall or something like that depending on your distro. This comes after all the kill scripts have been called to attempt to stop each service gracefully in turn. It will try kill -15 first, followed by kill -9.

Short answer: shutdown -h now or shutdown -r now are graceful. halt and reboot used to be non-graceful, but they will just call shutdown for you unless you use the -f option.

| improve this answer | |

No that is not true. shutdown changes init level which then runs all the shutdown scripts. What these scripts do depends on the script. But they normally don't terminate processes but send them the signal to end.

So this is the manual excerpt for shutdown:

   shutdown  brings  the system down in a secure way.  All logged-in users
   are notified that the system is going down, and  login(1)  is  blocked.
   It is possible to shut the system down immediately or after a specified
   delay.  All processes are first notified that the system is going  down
   by the signal SIGTERM.  This gives programs like vi(1) the time to save
   the file being edited, mail and news processing programs  a  chance  to
   exit  cleanly,  etc.   shutdown  does  its  job  by signalling the init
   process, asking it to change the runlevel.  Runlevel 0 is used to  halt
   the  system, runlevel 6 is used to reboot the system, and runlevel 1 is
   used to put to system into a state where administrative  tasks  can  be
   performed; this is the default if neither the -h or -r flag is given to
   shutdown.  To see which actions are taken on halt  or  reboot  see  the
   appropriate entries for these runlevels in the file /etc/inittab.
| improve this answer | |
  • 1
    Well, on most if not all distros I have used, the last thing the runlevel 6 (reboot) rc script does is run a global killall, to catch any lingering or hung processes. But this is run after all the normal stop scripts have completed. – adaptr Nov 4 '11 at 12:07
  • 2
    @adaptr Sure. But the processes had the chance to gracefully end. If they didn't there is no other possibility but to kill them. – mailq Nov 4 '11 at 12:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.