Multiple linux shutdown schedule and its behavior

If you're using the 'shutdown' command provided by systemd:

  • There is one centrally-managed shutdown timer (managed by the systemd-logind service). Trying to schedule a shutdown multiple times will just automatically cancel and replace the timeout & action with the new parameters.

  • shutdown +XX calls systemd-logind's ScheduleShutdown(), which sets or adjusts the timer.

  • shutdown -c calls systemd-logind's CancelScheduledShutdown(), which disables the timer.

If you're using the shutdown command from Linux sysvinit:

  • The program uses a pid-file to make sure a shutdown can only be scheduled once. If you try to run it twice, you should get the message "shutdown: already running". (Unless you accidentally deleted the pidfile that it uses to keep track of things.)

  • shutdown +XX refuses to start a new "queued shutdown" process if it finds one already running in background (according to the PID stored in /var/run/shutdown.pid).

  • shutdown -c kills exactly one "queued shutdown" process (whose PID is read from shutdown.pid), under the assumption that you shouldn't have been able to start more than one.