Subject: Re: Action of halt/reboot from scripts
To: None <current-users@NetBSD.ORG>
From: Geoff Wing <>
List: current-users
Date: 02/14/1998 06:44:57
Chris Jones <> typed:
:On Fri, 13 Feb 1998, Lennart Augustsson wrote:
:> > Yes, that produces the same outcome (using shutdown -fr now). The
:> > machine _looks_ as though it is shutting down from the messages on the
:> > console, but it doesn't get any further than killing most of the
:> > processes (This is from the CGI script, BTW).
:> I've had the same problem.  I've written a little program
:> that calls shutdown, but the machine doesn't shut down.
:> Some processes die, but then it hangs.  I've not tracked
:> down the problem, but I suspect that shutdown (and reboot)
:> manages to kill itself somehow.
:My guess is that shutdown (or halt or reboot) sends the proper signal to
:the kernel and thereby to init, whereupon processes start getting killed.
:Your shutdown/halt/reboot process won't get killed, but its parent will.
:Oops.  That sends a SIGHUP to shutdown, because its parent just died.  At
:that point, if shutdown isn't written to ignore SIGHUP, it'll die.  What
:this does to the shutdown system call, I can only guess.
:Assuming all of the above is true, you can do a "nohup shutdown -r now",
:and it should work just fine.

Shutdown does:
1. changes the priority of pid 0 to -20
2. forks with parent spewing child pid to stdout then exiting
3. waits until the requested time, if any (note 4.)
4. five minutes before the request time (or immediately if less), logons are
5. depending on flags (in order of priority)
  kill flag  ) nothing
  reboot flag) execs /sbin/reboot (static path)  with appropriate flags
  halt flag  ) execs /sbin/halt   (static path)  with appropriate flags
  otherwise  ) sends a TERM signal to init (pid 1) to go back to single user.
               This is the only signal it sends.

It does a couple more things prior to that but they're just trappings, eg.
fastboot, nosync, etc. 

Now as for reboot:
1. General cleanup: wtmp, sync, etc.
2. Send a TSTP signal to init (pid 1) to prevent new getty's and friends
3. ignore HUP signals
4. Send a TERM signal to everything else
5. sleep a bit, sync, sleep a bit
6. tries a couple of times to kill anything that didn't die
7. reboots

OK, after all that:  any problems you have with shutdown should be output
to stdout.  As for shutdown killing itself, it can't.  As for reboot killing
itself, nope, it got called by shutdown and will only receive proper signals
when shutdown dies.

Rebooting may take a bit of time, maybe up to a minute or more, if there are
processes around which refuse to die, but it will reboot.

Can you tell us what the last messages from shutdown are?
Geoff Wing   <>            Mobile : 0412 162 441 
Work URL:   Ego URL: