Bird
0
0

How can you detect if a Node.js child process was terminated by a signal instead of exiting normally?

hard📝 Application Q9 of 15
Node.js - Child Processes
How can you detect if a Node.js child process was terminated by a signal instead of exiting normally?
ACheck if the exit code is 0 in the 'exit' event
BCheck if the exit code is null and signal is not null in the 'exit' event
CListen to the 'error' event for signals
DUse child.kill() to detect signals
Step-by-Step Solution
Solution:
  1. Step 1: Understand exit event parameters

    The 'exit' event provides two parameters: exit code and signal name.
  2. Step 2: Identify signal termination condition

    If exit code is null and signal is not null, the process was terminated by that signal.
  3. Final Answer:

    Check if the exit code is null and signal is not null in the 'exit' event -> Option B
  4. Quick Check:

    Signal termination = code null + signal not null [OK]
Quick Trick: Signal termination means exit code null, signal set [OK]
Common Mistakes:
  • Assuming exit code 0 means signal termination
  • Listening to 'error' event for signals
  • Using child.kill() to detect signals

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes