Ask coding questions

← Back to all posts
Which signal is emitted when the STOP button is clicked ?
Unaty498 (1)

I'm part of a multiplayer repl with NodeJS, and we use a database to store informations, but when I stop the process, and when it stops automatically around 1AM GTM, Database is still open, and we lose data. My question is, how can I handle the STOP button press event in my code in order to execute some code before the repl stops (close database, deny transactions...)

Thank you.

Answered by programmeruser (571) [earned 5 cycles]
View Answer
programmeruser (571)

SIGKILL is emitted which cannot be caught (which would defeat the purpose).

Unaty498 (1)

@programmeruser So I can't handle it ? :(

programmeruser (571)

@Unaty498 no, due to how linux works.

Unaty498 (1)

@programmeruser So is there a way to configure the STOP button in order to make it emit SIGTERM or SIGINT instead of SIGKILL ?

Unaty498 (1)

@programmeruser oh, sad, but thanks for the answer anyway

Coder100 (17102)
process.on("exit", () => {


the signal is just your standard ^C (ctrl+c)

programmeruser (571)

@Coder100 it's not SIGINT it's SIGKILL so the above code will not work.