[Win32utils-devel] Process.kill and at_exit

Heesob Park phasis at gmail.com
Fri Jun 15 04:10:25 UTC 2012


Hi,

2012/6/13 Daniel Berger <djberg96 at gmail.com>

> I could have sworn our custom Process.kill implementation for signals
> 1 and 4-8 (the one that uses CreateRemoteThread + ExitProcess) allowed
> processes to call exit handlers. But it doesn't seem to be the case.
>
> # kill.rb
> require 'win32/process'
>
> cmd = "ruby -e 'sleep 3; at_exit{ puts \"done\" }"
> pid = Process.spawn(cmd)
>
> Process.kill(1, pid)
>
> But it doesn't seem that the at_exit block fires. Why not?
>
>
>
The at_exit block is called by ruby_finalize_0, ruby_finalize,
ruby_cleanup, rb_f_exit, rb_f_abort or rb_exit function.
Call ExitProcess with ruby process means skipping any of these functions.

After modifying CreateRemoteThread function in the process.rb like
following, you can see at_exit block fires.

thread = CreateRemoteThread(
                  handle,
                  0,
                  0,
                  GetProcAddress(GetModuleHandle('msvcrt-ruby191'),
'rb_f_exit'),
                  0,
                  0,
                  thread_id
                )

But you can also see the annoying error dialog.

Regards,
Park Heesob
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/win32utils-devel/attachments/20120615/47181bd9/attachment.html>


More information about the win32utils-devel mailing list