@@ -811,10 +811,14 @@ Dictionary OS_Unix::execute_with_pipe(const String &p_path, const List<String> &
811811#endif
812812}
813813
814- int OS_Unix::_wait_for_pid_completion (const pid_t p_pid, int *r_status, int p_options) {
814+ int OS_Unix::_wait_for_pid_completion (const pid_t p_pid, int *r_status, int p_options, pid_t *r_pid ) {
815815 while (true ) {
816- if (waitpid (p_pid, r_status, p_options) != -1 ) {
816+ pid_t pid = waitpid (p_pid, r_status, p_options);
817+ if (pid != -1 ) {
817818 // Thread exited normally.
819+ if (r_pid) {
820+ *r_pid = pid;
821+ }
818822 return 0 ;
819823 }
820824 const int error = errno;
@@ -838,10 +842,14 @@ bool OS_Unix::_check_pid_is_running(const pid_t p_pid, int *r_status) const {
838842 return false ;
839843 }
840844
845+ pid_t pid = -1 ;
841846 int status = 0 ;
842- const int result = _wait_for_pid_completion (p_pid, &status, WNOHANG);
847+ const int result = _wait_for_pid_completion (p_pid, &status, WNOHANG, &pid );
843848 if (result == 0 ) {
844849 // Thread is still running.
850+ if (pi && pid == p_pid) {
851+ pi->exit_code = WIFEXITED (status) ? WEXITSTATUS (status) : status;
852+ }
845853 return true ;
846854 }
847855
@@ -852,7 +860,9 @@ bool OS_Unix::_check_pid_is_running(const pid_t p_pid, int *r_status) const {
852860
853861 if (pi) {
854862 pi->is_running = false ;
855- pi->exit_code = status;
863+ if (pid == p_pid) {
864+ pi->exit_code = status;
865+ }
856866 }
857867
858868 if (r_status) {
0 commit comments