From: Joel VanderWerf Date: 2007-12-08T12:47:06+09:00 Subject: Re: at_exit() Inherited Across fork() James Gray wrote: > I guess it just kind of feels like the scripting language should be > doing something more clever for us here so we don't have to do this kind > of stuff though. I'd rather that ruby mirror the C API, and make it easy to add your own behavior on top of that. What about something like this? module Kernel def at_exit_in_this_process(&handler) unless $at_exit_in_this_process $at_exit_in_this_process = Hash.new{|h,k| h[k]=[]} at_exit do $at_exit_in_this_process[Process.pid].reverse_each do |hdlr| hdlr.call end end end $at_exit_in_this_process[Process.pid] << handler end end at_exit_in_this_process {p 1} fork do at_exit_in_this_process {p 2} end Process.wait -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407