Recall & Review
beginner
What does
fork do in Ruby?It creates a new child process that runs in parallel with the parent process. The child is a copy of the parent but runs independently.
Click to reveal answer
beginner
How can you tell if you are in the child or parent process after a
fork?The
fork method returns nil in the child process and the child's process ID (PID) in the parent process.Click to reveal answer
intermediate
Why use
Process.wait after forking?It makes the parent process wait for the child process to finish, ensuring the child completes before the parent continues or exits.
Click to reveal answer
beginner
What is a simple example of using
fork to run two tasks in parallel?You can
fork to create a child process that runs one task, while the parent runs another. Both run at the same time.Click to reveal answer
intermediate
What happens if you don't handle the child process after a
fork?The child process may become a 'zombie' process, which wastes system resources until the parent collects its exit status.
Click to reveal answer
What does the
fork method return in the parent process?✗ Incorrect
In the parent process,
fork returns the child's PID, allowing the parent to track the child.Which method should you use to wait for a child process to finish?
✗ Incorrect
Process.wait pauses the parent until the child process ends.What is the main benefit of using
fork in Ruby?✗ Incorrect
fork creates a new process so tasks can run at the same time.What value does
fork return in the child process?✗ Incorrect
In the child process,
fork returns nil.What problem occurs if the parent does not wait for the child process?
✗ Incorrect
Without waiting, child processes can become zombies, using system resources unnecessarily.
Explain how
fork helps run tasks in parallel in Ruby.Think about how two people can work on different parts of a project at the same time.
You got /4 concepts.
Describe why it is important to use
Process.wait after forking.Imagine waiting for your friend to finish before leaving a party together.
You got /3 concepts.