Skip to content

Instantly share code, notes, and snippets.

@tj
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tj/41545c718f8a8256f8f5 to your computer and use it in GitHub Desktop.
Save tj/41545c718f8a8256f8f5 to your computer and use it in GitHub Desktop.
function shutdown() {
var times = 0;
process.on('SIGINT', function(){
trapped('INT');
});
process.on('SIGQUIT', function(){
trapped('QUIT');
});
function trapped(sig) {
switch (++times) {
case 1:
console.log('signal received: %s', sig);
break;
case 2:
console.log('second signal received: %s', sig);
console.log('forcing exit');
process.exit(1);
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment