Skip to content

Instantly share code, notes, and snippets.

@jc00ke
Forked from cwgem/simple_fork.rb
Created December 1, 2011 02:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jc00ke/1413045 to your computer and use it in GitHub Desktop.
Save jc00ke/1413045 to your computer and use it in GitHub Desktop.
Simple Fork Example
# 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