Bird
0
0

How can you modify the forked child process to handle multiple messages and respond to each one separately?

hard📝 Application Q9 of 15
Node.js - Child Processes
How can you modify the forked child process to handle multiple messages and respond to each one separately?
AUse a loop in parent to send all messages at once without waiting
BAdd a listener for 'message' event in child that processes each message and sends a response
CRestart the child process for each message to reset state
DSend all messages as a single array and process once in child
Step-by-Step Solution
Solution:
  1. Step 1: Understand message handling in child

    Child can listen for 'message' events multiple times and respond to each message separately.

  2. Step 2: Evaluate other options

    Sending all messages at once without waiting can cause race conditions, restarting child is inefficient, sending all messages as array changes protocol.

  3. Final Answer:

    Add a listener for 'message' event in child that processes each message and sends a response -> Option B
  4. Quick Check:

    Multiple message handling = event listener in child [OK]

Quick Trick: Child listens to 'message' event to handle multiple messages [OK]
Common Mistakes:
  • Restarting child for each message
  • Sending all messages at once without protocol
  • Not using event listener in child

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes