1

Reading one of Stephen's excellent replies,

When the operating system shuts down, processes are shut down using SIGTERM and SIGKILL, but those signals don’t come from the kernel (or not directly — calling kill() with a pid of 0 or a negative pid will result in the kernel sending the signal to a number of processes). They come from a service manager terminating its services and from various last-ditch-kill-everything application-mode programs that are part of the system management mechanism: e.g. the killprocs van Smoorenburg rc script, the killprocs OpenRC script, and the systemd-shutdown program.

When the OS shuts down,

  • How does a service manager know that it should terminates its services? Is the service manager notified by receiving SIGKILL or SIGTERM or some other signal from the kernel or some process?

  • Similarly how do various last-ditch-kill-everything application-mode programs that are part of the system management mechanism know that they should send out SIGTERM and SIGKILL?

Thanks.

  • Some process talking to service manager, by IPC, not necessarily signals. – 炸鱼薯条德里克 Dec 18 '18 at 6:22
2

A service manager knows it should terminate its services because the system administrator asked it to halt or reboot the system. When the administrator runs reboot, or the user chooses the corresponding option in his/her desktop environment, the init process is told to reboot (not the kernel, at this point). The init process takes care of everything it’s been configured to do before asking the kernel to actually reboot.

The last-ditch, kill-everything phase is part of the shutdown procedure: once the shutdown procedure has asked all running services to stop, it typically waits a short while, then kills any remaining processes.

The various init systems have different implementations of all this. With sysvinit, halting or rebooting is a runlevel transition, started by asking the running init to switch to the appropriate runlevel (see the telinit manpage for details). With systemd, it’s a target, which ends up running the systemd-halt service.

  • Thanks. Does reboot notify init process to reboot, by sending some signal to init? Does init process notify a service manager to terminate its services, by execve() on the service manager with some argument, instead of sending some signal to the service manager process? – Tim Dec 18 '18 at 6:02
  • 1
    That depends on the init system being used. See the links for details. – Stephen Kitt Dec 18 '18 at 6:15
  • @Tim systemd use dbus to communicate with systemctl(or you may call it as reboot). I don't understand your statement of "execve() on some process". systemd IS BOTH the init and service manager, and it has complex logic to terminate your services, including pre-defined actions in unit files and signals. – 炸鱼薯条德里克 Dec 18 '18 at 6:18
  • "When the administrator runs reboot, or the user chooses the corresponding option in his/her desktop environment, the init process is told to reboot." How is the init process told to reboot? What if systemd? – Tim Dec 18 '18 at 14:32
  • Is reboot running in its own process? How does it notify the init process? By some signal? – Tim Dec 18 '18 at 14:38

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.