[Win32utils-devel] Process.kill and at_exit

Daniel Berger djberg96 at gmail.com
Sat Jun 16 01:35:34 UTC 2012


On Thu, Jun 14, 2012 at 10:10 PM, Heesob Park <phasis at gmail.com> wrote:
> 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.

Thanks for this! I'm rewriting Process.kill using FFI, and now I'm
thinking I might want to alter the interface so that people can pass
in more types of arguments.

Regards,

Dan


More information about the win32utils-devel mailing list