On Sun, 9 Jul 2017, Janne Johansson wrote:

> One guess would be that the post-sync() sleep might give "async" devices a
> chance to flush out I/O, so shortening that one just because no pid is
> killable might change peoples experiences.

There are actually two sync calls, the first is before the first sleep. 
But more importantly, waiting for devices to flush out I/O should be done 
by the respective drivers in the kernel. That way the wait only affects 
those people who need it. I will send a separate mail about this.

> 
> 
> 2017-07-09 9:42 GMT+02:00 Stefan Fritsch <s...@sfritsch.de>:
> 
> > 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);
> >
> >
> 
> 
> 

Reply via email to