Bug 26362 - [Process] Exited event raised while process still running
Summary: [Process] Exited event raised while process still running
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: mscorlib ()
Version: 3.12.0
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: marcos.henrich
URL:
Depends on:
Blocks:
 
Reported: 2015-01-23 17:03 UTC by Sandy Armstrong [MSFT]
Modified: 2015-04-27 14:14 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Sandy Armstrong [MSFT] 2015-01-23 17:03:10 UTC
1. Get a process from GetProcessById or GetProcesses
2. Set EnableRaisingEvents to true
3. Add a handler for the Exited event

Expected results:

Exited event handler is called when the associated process exits.

Actual results:

Exited event handler is triggered almost immediately.


Example:

	var cp = Process.GetCurrentProcess ();

	foreach (var p in Process.GetProcesses ()) {
		try {
			if (p.Id != cp.Id && !p.HasExited) {
				Console.WriteLine ("Name: {0} StartTime: {1}", p.ProcessName, p.StartTime);
				if (p.ProcessName.StartsWith ("ssh-agent")) {
					p.EnableRaisingEvents = true;
					p.Exited += (s, e) => {
						Console.WriteLine ("ssh-agent exited");
					};
				}
			}
		} catch {
		}
	}


Output (even though ssh-agent is still very much alive):

    Name: ssh-agent StartTime: 12/31/1600 4:00:00 PM
    Name: lldb StartTime: 12/31/1600 4:00:00 PM
    ssh-agent exited
Comment 1 Sandy Armstrong [MSFT] 2015-01-23 17:12:06 UTC
Works on MS.NET, not Mono 3.12.0 on OS X Yosemite.
Comment 2 marcos.henrich 2015-04-08 09:48:47 UTC
Hi Sandy,

Thanks for the bug report.

The fix to this issue can be found in the following pull request:
https://github.com/mono/mono/pull/1691
Comment 3 marcos.henrich 2015-04-27 14:14:38 UTC
Fixed in master e097a98f3bd9082c7d03fa580b604c0228b4ad67.
https://github.com/mono/mono/commit/e097a98f3bd9082c7d03fa580b604c0228b4ad67