[Mono-list] Strange behavior of Process exit events

Nicholas Frechette zeno490 at gmail.com
Mon Oct 3 10:32:14 EDT 2011


Hi,
Over the weekend, I noticed the following behavior in my application.
I run the latest mono on top of ubuntu 11.04. (Dual installation)

I have an application A that launches a child application B (both C#,
both mono).
Over STD IN/OUT I transfer to application B the PID of application A.
The idea is to have application B monitor its parent, application A,
and in the event where A terminates in a non graceful way, B would
detect that event and terminate gracefully.

In an attempt to do this, I use Process::GetProcessById (or whatever
the API is, I'm writing this from memory). It finds the process for A
correctly.
If I set the flag to raise events and register a handler for
Process::Exited event, the event fires almost immediately. (If I do
not set the flag for raise events, the Exited event is never fired,
even when A terminates)
If I launch a thread and call WaitForExit(), the function returns
right away as well.

The only way I could make it work was to launch a thread with the following:
while (!ProcessA.HasExited) Thread.Sleep(500);

The HasExited variable seems to be updated properly and it works 100%
as expected.
I found this quite strange and searching on the internet, I couldn't
find anything quite similar.
Application A uses the Process:Exited event to monitor application B
and that seems to work properly when the monitored process is launched
from the monitoring process.

I looked at bug reports and couldn't find anything related either. Has
someone else noticed the above behavior?
Is the behavior the same on .NET/Windows?

Thanks,
Nicholas


More information about the Mono-list mailing list