Hi, what about only waiting for processes to die on reboot if there are any processes left? Nice for the frequently rebooting kernel developer.
This usually saves at least one second and often 4-5 seconds when calling reboot via ssh or 'exec reboot' from a console (otherwise the parent shell won't exit before the first SIGKILL). ok? Cheers, Stefan diff --git sbin/reboot/reboot.c sbin/reboot/reboot.c index dd85d0d9c8c..5556514295e 100644 --- sbin/reboot/reboot.c +++ sbin/reboot/reboot.c @@ -57,6 +57,17 @@ int dohalt; #define _PATH_RC "/etc/rc" +static void +sleep_while_procs(int seconds) +{ + while (seconds > 0) { + if (kill(-1, 0) == -1 && errno == ESRCH) + return; + sleep(1); + seconds--; + } +} + int main(int argc, char *argv[]) { @@ -232,10 +243,10 @@ main(int argc, char *argv[]) * buffers on their way. Wait 5 seconds between the SIGTERM and * the SIGKILL to give everybody a chance. */ - sleep(2); + sleep_while_procs(2); if (!nflag) sync(); - sleep(3); + sleep_while_procs(3); for (i = 1;; ++i) { if (kill(-1, SIGKILL) == -1) { @@ -247,7 +258,7 @@ main(int argc, char *argv[]) warnx("WARNING: some process(es) wouldn't die"); break; } - (void)sleep(2 * i); + sleep_while_procs(2 * i); } reboot(howto);