-
-
Save jc00ke/1413045 to your computer and use it in GitHub Desktop.
Simple Fork Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Parent process | |
puts "Hello from parent: #$$" | |
3.times do | |
fork do | |
# child process logic here | |
trap('INT') do | |
puts "Exiting from child: #$$" | |
exit | |
end | |
loop { puts "Hello from child: #$$"; sleep 3 } | |
# end child process logic | |
end | |
end | |
# Parent process logic continues | |
trap('INT') do | |
puts "Exiting from parent: #$$" | |
exit | |
end | |
Process.waitall |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment