Skip to content

Instantly share code, notes, and snippets.

@chrismo
Created November 27, 2012 22:25
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 chrismo/4157576 to your computer and use it in GitHub Desktop.
Save chrismo/4157576 to your computer and use it in GitHub Desktop.
all(?) things at_exit and otherwise
18930: Parent
18933: Child A
18934: Child B
18933: END in child if only exit called
18933: at_exit in child if only exit called
18933: parent END (only one)
18933: parent at_exit (2 times)
18933: parent at_exit (2 times)
18930: parent: child died
18930: parent trap(0)
18930: parent END (only one)
18930: parent at_exit (2 times)
18930: parent at_exit (2 times)
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment