When the operating system shuts down, how does a service manager know that it should sends SIGTERM and...












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.










share|improve this question






















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
















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.










share|improve this question






















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














1












1








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.










share|improve this question













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.







linux kernel services shutdown






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 18 at 5:38









Tim

26k74246455




26k74246455












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


















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
















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




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










1 Answer
1






active

oldest

votes


















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.






share|improve this answer























  • 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 at 6:02






  • 1




    That depends on the init system being used. See the links for details.
    – Stephen Kitt
    Dec 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 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 at 14:32










  • Is reboot running in its own process? How does it notify the init process? By some signal?
    – Tim
    Dec 18 at 14:38











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f489610%2fwhen-the-operating-system-shuts-down-how-does-a-service-manager-know-that-it-sh%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









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.






share|improve this answer























  • 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 at 6:02






  • 1




    That depends on the init system being used. See the links for details.
    – Stephen Kitt
    Dec 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 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 at 14:32










  • Is reboot running in its own process? How does it notify the init process? By some signal?
    – Tim
    Dec 18 at 14:38
















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.






share|improve this answer























  • 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 at 6:02






  • 1




    That depends on the init system being used. See the links for details.
    – Stephen Kitt
    Dec 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 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 at 14:32










  • Is reboot running in its own process? How does it notify the init process? By some signal?
    – Tim
    Dec 18 at 14:38














2












2








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.






share|improve this answer














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.







share|improve this answer














share|improve this answer



share|improve this answer








edited Dec 18 at 6:13

























answered Dec 18 at 5:49









Stephen Kitt

164k24365444




164k24365444












  • 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 at 6:02






  • 1




    That depends on the init system being used. See the links for details.
    – Stephen Kitt
    Dec 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 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 at 14:32










  • Is reboot running in its own process? How does it notify the init process? By some signal?
    – Tim
    Dec 18 at 14:38


















  • 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 at 6:02






  • 1




    That depends on the init system being used. See the links for details.
    – Stephen Kitt
    Dec 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 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 at 14:32










  • Is reboot running in its own process? How does it notify the init process? By some signal?
    – Tim
    Dec 18 at 14:38
















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 at 6:02




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 at 6:02




1




1




That depends on the init system being used. See the links for details.
– Stephen Kitt
Dec 18 at 6:15




That depends on the init system being used. See the links for details.
– Stephen Kitt
Dec 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 at 6:18




@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 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 at 14:32




"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 at 14:32












Is reboot running in its own process? How does it notify the init process? By some signal?
– Tim
Dec 18 at 14:38




Is reboot running in its own process? How does it notify the init process? By some signal?
– Tim
Dec 18 at 14:38


















draft saved

draft discarded




















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f489610%2fwhen-the-operating-system-shuts-down-how-does-a-service-manager-know-that-it-sh%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Morgemoulin

Scott Moir

Souastre