Getting notification that a subprocess is killed on Windows

R

Ralph Shnelvar

[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?


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 = $?
 
C

Charles Calvert

[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>.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top