misc collection of ruby at_exit fu
puts "#{Process.pid}: Parent"
2.times { at_exit { puts "#{Process.pid}: parent at_exit (2 times)" } }
2.times { END { puts "#{Process.pid}: parent END (only one)" } }
trap(0) { puts "#{Process.pid}: parent trap(0)" }
trap('CLD') { puts "#{Process.pid}: parent: child died" }
fork {
puts "#{Process.pid}: Child A"
at_exit { puts "#{Process.pid}: at_exit in child if only exit called" }
END { puts "#{Process.pid}: END in child if only exit called" }
trap(0) { "#{Process.pid}: trap(0) in child - NEVER HAPPENS" }
exit
}
fork {
puts "#{Process.pid}: Child B"
at_exit { puts "#{Process.pid}: at_exit - NEVER HAPPENS" }
END { puts "#{Process.pid}: END in child - NEVER HAPPENS" }
trap(0) { "#{Process.pid}: trap(0) in child - NEVER HAPPENS" }
exit!
}
Process.wait
Written by chrismo
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Related Tags
#ruby
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#