[VM/IO] The exit code handler thread should not try to get the exit codes for detached child processes. Currently we end up in a tight loop in the exit code handler when detached processes are created.

Change-Id: I0eb207c4421d9e22e62ffd5a53478cf1553a3188
Reviewed-on: https://dart-review.googlesource.com/c/78701
Reviewed-by: Zach Anderson <zra@google.com>
Commit-Queue: Siva Annamalai <asiva@google.com>
diff --git a/runtime/bin/process_android.cc b/runtime/bin/process_android.cc
index 7afd0ee..d379d2d 100644
--- a/runtime/bin/process_android.cc
+++ b/runtime/bin/process_android.cc
@@ -315,11 +315,11 @@
 
     // This runs in the original process.
 
-    // Be sure to listen for exit-codes, now we have a child-process.
-    ExitCodeHandler::ProcessStarted();
-
-    // Register the child process if not detached.
+    // If the child process is not started in detached mode, be sure to
+    // listen for exit-codes, now that we have a non detached child process
+    // and also Register this child process.
     if (Process::ModeIsAttached(mode_)) {
+      ExitCodeHandler::ProcessStarted();
       err = RegisterProcess(pid);
       if (err != 0) {
         return err;
diff --git a/runtime/bin/process_linux.cc b/runtime/bin/process_linux.cc
index b889c28..825bc1d 100644
--- a/runtime/bin/process_linux.cc
+++ b/runtime/bin/process_linux.cc
@@ -315,11 +315,11 @@
 
     // This runs in the original process.
 
-    // Be sure to listen for exit-codes, now we have a child-process.
-    ExitCodeHandler::ProcessStarted();
-
-    // Register the child process if not detached.
+    // If the child process is not started in detached mode, be sure to
+    // listen for exit-codes, now that we have a non detached child process
+    // and also Register this child process.
     if (Process::ModeIsAttached(mode_)) {
+      ExitCodeHandler::ProcessStarted();
       err = RegisterProcess(pid);
       if (err != 0) {
         return err;
diff --git a/runtime/bin/process_macos.cc b/runtime/bin/process_macos.cc
index d997e01..d83443a 100644
--- a/runtime/bin/process_macos.cc
+++ b/runtime/bin/process_macos.cc
@@ -309,11 +309,11 @@
 
     // This runs in the original process.
 
-    // Be sure to listen for exit-codes, now we have a child-process.
-    ExitCodeHandler::ProcessStarted();
-
-    // Register the child process if not detached.
+    // If the child process is not started in detached mode, be sure to
+    // listen for exit-codes, now that we have a non detached child process
+    // and also Register this child process.
     if (Process::ModeIsAttached(mode_)) {
+      ExitCodeHandler::ProcessStarted();
       err = RegisterProcess(pid);
       if (err != 0) {
         return err;