Challenge - 5 Problems
Child Process Exit Code Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the exit code of a child process that ends normally?
Consider a Node.js child process that runs a script which completes without errors. What exit code will the child process emit?
Node.js
const { spawn } = require('child_process');
const child = spawn('node', ['-e', 'console.log("done")']);
child.on('exit', (code) => {
console.log('Exit code:', code);
});Attempts:
2 left
💡 Hint
Normal completion usually returns zero as exit code.
✗ Incorrect
When a child process finishes successfully without errors, it exits with code 0. This is a standard convention indicating success.
❓ Predict Output
intermediate2:00remaining
What exit code does a child process emit if terminated by signal SIGTERM?
If a Node.js child process is killed by the SIGTERM signal, what will be the exit code value received in the 'exit' event?
Node.js
const { spawn } = require('child_process');
const child = spawn('node', ['-e', 'setTimeout(() => {}, 10000)']);
child.on('exit', (code, signal) => {
console.log('Exit code:', code);
console.log('Signal:', signal);
});
child.kill('SIGTERM');Attempts:
2 left
💡 Hint
When a process is terminated by a signal, exit code is null and signal is set.
✗ Incorrect
If a child process is terminated by a signal like SIGTERM, the exit code is null and the signal name is provided instead.
❓ component_behavior
advanced2:00remaining
How does Node.js child process handle exit codes on Windows vs Unix?
Which statement correctly describes the difference in exit code behavior of Node.js child processes on Windows compared to Unix-like systems?
Attempts:
2 left
💡 Hint
Unix systems use exit codes greater than 127 to indicate signals, Windows does not.
✗ Incorrect
Unix systems use exit codes greater than 127 to indicate termination by signals, while Windows only uses positive integers for exit codes.
🔧 Debug
advanced2:00remaining
Why does this child process exit event show code null and signal null?
Examine the code below. The child process exits but both code and signal are null. What is the most likely cause?
Node.js
const { spawn } = require('child_process');
const child = spawn('node', ['-e', 'process.exit()']);
child.on('exit', (code, signal) => {
console.log('Exit code:', code);
console.log('Signal:', signal);
});Attempts:
2 left
💡 Hint
process.exit() with no argument defaults to exit code 0.
✗ Incorrect
Calling process.exit() without an argument exits with code 0. The exit event should receive code 0, so code being null indicates a logging or event handling mistake.
🧠 Conceptual
expert2:00remaining
What is the meaning of exit code 130 in a Node.js child process?
A Node.js child process exits with code 130. What does this code represent?
Attempts:
2 left
💡 Hint
Exit code 130 is 128 + signal number for SIGINT.
✗ Incorrect
Exit code 130 means the process was terminated by signal 2 (SIGINT). Exit codes for signals are 128 plus the signal number.