Bird
0
0

What will happen if you try to fork a non-existent file like nofile.js?

medium📝 component behavior Q5 of 15
Node.js - Child Processes
What will happen if you try to fork a non-existent file like nofile.js?
AThe child process is created but does nothing
BThe child process runs with empty code
CThe parent process silently ignores the error
DThe parent process throws an error immediately
Step-by-Step Solution
Solution:
  1. Step 1: Understand fork error behavior

    fork() returns a ChildProcess instance synchronously, but if the file does not exist, the child process emits an 'error' event (ENOENT) and exits without running code.

  2. Step 2: Check other options

    A: no synchronous throw in parent; B: does not run empty code; C: error is emitted asynchronously on child.

  3. Final Answer:

    The child process is created but does nothing -> Option A
  4. Quick Check:

    fork missing file = child created but exits [OK]

Quick Trick: fork creates child but emits error/exits if file missing [OK]
Common Mistakes:
  • Thinking parent throws immediately
  • Child runs empty code
  • Parent silently ignores

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes