Bird
0
0

Identify the error in this Ruby code snippet:

medium📝 Debug Q6 of 15
Ruby - Concurrent Programming
Identify the error in this Ruby code snippet:
pid = fork do
  puts 'Child'
end
Process.wait
AProcess.wait requires a PID argument to wait for the specific child
Bfork block syntax is incorrect
Cputs cannot be used inside fork
DProcess.wait should be Process.waitall
Step-by-Step Solution
Solution:
  1. Step 1: Check Process.wait usage

    Process.wait without a PID argument waits for any child, but to wait for this specific child it requires the pid argument.
  2. Step 2: Confirm fork block and puts are valid

    Fork block syntax and puts inside are correct; no syntax error there.
  3. Final Answer:

    Process.wait requires a PID argument -> Option A
  4. Quick Check:

    Process.wait needs PID for specific child [OK]
Quick Trick: Pass PID to Process.wait to wait for specific child [OK]
Common Mistakes:
  • Omitting PID argument causes unexpected waits
  • Thinking fork block syntax is wrong
  • Believing puts can't run in child

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes