From: Park Heesob Date: 2006-11-10T19:27:50+09:00 Subject: Re: win32/process question Hi, >From: J-Van >Reply-To: ruby-talk@ruby-lang.org >To: ruby-talk@ruby-lang.org (ruby-talk ML) >Subject: Re: win32/process question >Date: Fri, 10 Nov 2006 15:23:58 +0900 > >I guess I should note that this is after I require 'win32/process' >(which is installed via a gem). > >On 11/9/06, J-Van wrote: >>On Windows XP, Ruby 1.8.5: >> >># start notepad >>irb(main):003:0> info = Process.create :app_name => "notepad" >>=> #>thread_handle=1912, process_id=3536, thread_id=3088> >> >># notepad running >>irb(main):004:0> Process.kill 0, info.process_id >>=> [3536] >> >># kill notepad >>irb(main):005:0> Process.kill 9, info.process_id >>=> [3536] >> >># notepad's dead, but why doesn't this throw an exception?! >>irb(main):006:0> Process.kill 0, info.process_id >>=> [3536] >> >>Any ideas? >>Thanks, >>Joe >> > Refer to http://msdn2.microsoft.com/fr-fr/library/ms686722.aspx, "While open handles to kernel objets are closed automatically when a process terminates, the objects themselves exist until all open handles to them are closed. Therefore, an object will remain valid after a process that is using it terminates if another process has an open handle to it." Here is the working code. irb(main):001:0> require 'win32/process' => true irb(main):002:0> include Windows::Handle => Object irb(main):003:0> info = Process.create :app_name=>'notepad' => # irb(main):004:0> Process.kill 0,info.process_id => [1748] irb(main):005:0> Process.kill 9,info.process_id => [1748] irb(main):006:0> CloseHandle(info.process_handle) => true irb(main):007:0> CloseHandle(info.thread_handle) => true irb(main):008:0> Process.kill 0,info.process_id ProcessError: The parameter is incorrect. from c:/ruby/lib/ruby/gems/1.8/gems/win32-process-0.5.1/lib/win32/proces s.rb:156:in `kill' from c:/ruby/lib/ruby/gems/1.8/gems/win32-process-0.5.1/lib/win32/proces s.rb:132:in `each' from c:/ruby/lib/ruby/gems/1.8/gems/win32-process-0.5.1/lib/win32/proces s.rb:132:in `kill' from (irb):8 Regards, Park Heesob _________________________________________________________________ Don't just search. Find. Check out the new MSN Search! http://search.msn.click-url.com/go/onm00200636ave/direct/01/