Score:1

Does the OS stop all PIDs before restarted when the user clicks restart in Ubuntu?

in flag

I have a server written in Node.js listening to SIGTERM and SIGINT events. I'm wondering id the Ubuntu stops all PIDs (or which PIDs) it stops before restarting. So for example if my node process listens to those events and wants to gracefully shutdown but gracefully shutting down will take awhile how long do I have before the OS force kills it.

Score:1
cz flag

If you choose to shutdown or reboot the system, then systemd will send your process a SIGTERM signal first. If it doesn't react to SIGTERM within a certain amount of time, it will send SIGINT, and if it still doesn't respond to that it will eventually send SIGKILL. I believe the times are 90 seconds and 5 minutes respectively, but I can't find the relevant docs, it's been quite a while since I profiled shutdown, and I don't want to profile shutdown again right now...

Quesofat avatar
in flag
That's super helpful!!!!! Thanks!
Score:1
cn flag

Sending signals to all processes is very late in system shutdown. Most registered processes will already have been stopped by a service manager. systemd for Ubuntu and other Linux distros, but possibly something else like supervisord or PM2.

Get your application registered with a service manager, and configure it to be stopped with the desired behavior. systemd services definitely can define the stop command, which signals are sent, and how long to wait before sending kill.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.