Skip to content
← Back to Community
Which signal is emitted when the STOP button is clicked ?
Profile icon
Unaty498

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 [earned 5 cycles]
View Answer
Voters
Profile icon
NanderTGA
Profile icon
Unaty498
Comments
hotnewtop
Profile icon
programmeruser

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

Profile icon
Unaty498

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

Profile icon
programmeruser

@Unaty498 no, due to how linux works.

Profile icon
Unaty498

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

Profile icon
programmeruser

@Unaty498 unfortunately, no.

Profile icon
Unaty498

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

Profile icon
AnshikaSinghal

my emit is not working in replit to code faster please help

Profile icon
Coder100
process.on("exit", () => { })

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

Profile icon
programmeruser

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

Profile icon
Coder100