Getting notification that a subprocess is killed on Windows

What is the proper way, under Windows, to detect that a process was
killed? Crashed?

  Signal.list.each_key do |key|
    puts key
    Signal.trap(key, lambda {|signo| puts "#{key}: pid #{$$} with 

signo #{signo}"})
end
@the_command_pipe = IO.popen(the_command)
@the_command_pid = @the_command_pipe.pid
Process.waitpid(@the_command_pid)
@child_process_return_status = $?
.
.
.

Process.kill(:KILL, @the_command_pid)    # Seems to properly kill my 

process

All that is TRAP’d is EXIT. Worse,
@child_process_return_status.exitstatus is zero.

On Fri, 3 Sep 2010 11:07:14 -0500, Ralph S. [email protected]
wrote in [email protected]:

[Note: parts of this message were removed to make it a legal post.]

What is the proper way, under Windows, to detect that a process was killed? Crashed?

[snip code]

All that is TRAP’d is EXIT. Worse, @child_process_return_status.exitstatus is zero.

To get any level of detail for something like this, you’re going to
have to use the Windows API directly or perhaps via the .NET stack
(using IronRuby).

The following article contains code for doing this using C++ and the
Win32 API. Note that it implements a process monitor, which may be
more than you’re trying to do.

http://www.codeproject.com/KB/threads/procmon.aspx

If you just want to monitor a single process, have a look at the API
function WaitForSingleObject
http://msdn.microsoft.com/en-us/library/ms687032(VS.85).aspx.

Also, check this article for the function named TerminateApp() (ignore
the stuff with “16” in the name - it’s for 16/32 bit versions of
Windows like Windows95). http://support.microsoft.com/kb/178893.

On 3 September 2010 17:07, Ralph S. [email protected] wrote:

What is the proper way, under Windows, to detect that a process was killed? Â Crashed?

Have you had a look at win32-process, one of the Win32Utils?

http://win32utils.rubyforge.org/

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs