private bool TryReapChild()
        {
            lock (_gate)
            {
                if (_exited)
                {
                    return(false);
                }

                // Try to get the state of the child process
                int exitCode;
                int waitResult = Interop.Sys.WaitPidExitedNoHang(_processId, out exitCode);

                if (waitResult == _processId)
                {
                    _exitCode = exitCode;

                    if (_usesTerminal)
                    {
                        // Update terminal settings before calling SetExited.
                        Process.ConfigureTerminalForChildProcesses(-1);
                    }

                    SetExited();

                    return(true);
                }
                else if (waitResult == 0)
                {
                    // Process is still running
                }
                else
                {
                    // Unexpected.
                    int errorCode = Marshal.GetLastWin32Error();
                    Environment.FailFast("Error while reaping child. errno = " + errorCode);
                }
                return(false);
            }
        }