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

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.


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...


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.