Skip to content

process: Send signal name to signal handlers

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

process

Description

Allow the signal handler to receive the signal code that triggered the handler.

This is useful in situations where you have one common signal handler to gracefully exit a Node.js process (ie. one handler for SIGINT and SIGTERM) and you still want to know exactly which signal was used to stop the process.

Before
function shutdown(signal) {
  // Clean up resources
  console.log(`Quit - received ${signal}`)
}

process.once('SIGTERM', () => shutdown('SIGTERM'))
process.once('SIGINT', () => shutdown('SIGINT'))
After
function shutdown(signal) {
  // Clean up resources
  console.log(`Quit - received ${signal}`)
}

process.once('SIGTERM', shutdown)
process.once('SIGINT', shutdown)

Merge request reports

Loading