0
0
Node.jsframework~20 mins

Child process exit codes in Node.js - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Child Process Exit Code Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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);
});
AExit code: 1
BExit code: null
CExit code: 0
DExit code: undefined
Attempts:
2 left
💡 Hint
Normal completion usually returns zero as exit code.
Predict Output
intermediate
2: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');
AExit code: null, Signal: SIGTERM
BExit code: 143, Signal: null
CExit code: 1, Signal: SIGTERM
DExit code: 0, Signal: null
Attempts:
2 left
💡 Hint
When a process is terminated by a signal, exit code is null and signal is set.
component_behavior
advanced
2: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?
ABoth Windows and Unix treat exit codes identically with no difference.
BOn Unix, exit codes are always positive; on Windows, exit codes can be negative for signals.
CWindows uses signals for exit codes; Unix uses only numeric codes.
DOn Windows, exit codes are always positive integers; on Unix, codes greater than 127 indicate signals.
Attempts:
2 left
💡 Hint
Unix systems use exit codes greater than 127 to indicate signals, Windows does not.
🔧 Debug
advanced
2: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);
});
AThe child process exited normally with code 0, but code is incorrectly logged as null.
BThe child process was terminated by a signal, but signal name is missing.
CThe child process called process.exit() without an argument, so code is null.
DThe child process did not exit properly, causing both code and signal to be null.
Attempts:
2 left
💡 Hint
process.exit() with no argument defaults to exit code 0.
🧠 Conceptual
expert
2: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?
AThe process completed successfully with warnings.
BThe process was terminated by SIGINT (Ctrl+C).
CThe process was terminated by SIGTERM.
DThe process crashed due to an uncaught exception.
Attempts:
2 left
💡 Hint
Exit code 130 is 128 + signal number for SIGINT.