Bug 6291 - OSX: use KQueue to correctly support Process' WaitForExit and Exited event on external processes.
Summary: OSX: use KQueue to correctly support Process' WaitForExit and Exited event on...
Alias: None
Product: Runtime
Classification: Mono
Component: io-layer ()
Version: unspecified
Hardware: PC Mac OS
: Low normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2012-07-25 20:07 UTC by Alex Corrado [MSFT]
Modified: 2017-07-12 23:47 UTC (History)
5 users (show)

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

Testcase (1.18 KB, application/octet-stream)
2012-07-25 20:07 UTC, Alex Corrado [MSFT]

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:

Description Alex Corrado [MSFT] 2012-07-25 20:07:58 UTC
Created attachment 2258 [details]

The Process object obtained by Process.GetProcessById on OSX does not behave correctly. Specifically, the Exited event fires immediately after it is assigned and EnableRaisingEvents is set. Also, WaitForExit returns immediately.

Attached is a little test case. Here is the result I see from running it:

alex@dynamic-028:Desktop $ mcs foo.cs
alex@dynamic-028:Desktop $ mono foo.exe 
Child pid: 6567
Child pid: 6568
Grandchild pid: 6568
Elapsed ms: 33
alex@dynamic-028:Desktop $ ps -A |grep mono
 6568 ttys005    0:00.01 /usr/bin/mono /Users/alex/Desktop/foo.exe 2
 6573 ttys005    0:00.00 grep mono

(It returns immediately even though the grandchild process was sleeping for 10sec.)
Comment 1 Rolf Bjarne Kvinge [MSFT] 2012-07-25 20:13:34 UTC
This is a known limitation. 

The problem is that it is only possible to call waitpid on child processes, so the only other way of waiting is to poll for pid existance (and this has not been implemented).
Comment 2 Alex Corrado [MSFT] 2012-07-26 12:20:27 UTC
We might use kqueue(2) on OSX
Comment 4 Rodrigo Kumpera 2017-07-12 23:47:09 UTC
We gave up on kqueue due to the file descriptor limit. We're now going to do it using the CoreFX implementation instead that uses FSEvent.