| 1577 | } |
| 1578 | |
| 1579 | inline int Popen::poll() noexcept(false) |
| 1580 | { |
| 1581 | #ifdef __USING_WINDOWS__ |
| 1582 | int ret = WaitForSingleObject(process_handle_, 0); |
| 1583 | if (ret != WAIT_OBJECT_0) return -1; |
| 1584 | |
| 1585 | DWORD dretcode_; |
| 1586 | if (FALSE == GetExitCodeProcess(process_handle_, &dretcode_)) |
| 1587 | throw OSError("GetExitCodeProcess", 0); |
| 1588 | |
| 1589 | retcode_ = (int)dretcode_; |
| 1590 | CloseHandle(process_handle_); |
| 1591 | |
| 1592 | return retcode_; |
| 1593 | #else |
| 1594 | if (!child_created_) return -1; // TODO: ?? |
| 1595 | |
| 1596 | int status; |
| 1597 | |
| 1598 | // Returns zero if child is still running |
| 1599 | int ret = waitpid(child_pid_, &status, WNOHANG); |
| 1600 | if (ret == 0) return -1; |
| 1601 | |
| 1602 | if (ret == child_pid_) { |
| 1603 | if (WIFSIGNALED(status)) { |
| 1604 | retcode_ = WTERMSIG(status); |
| 1605 | } else if (WIFEXITED(status)) { |
| 1606 | retcode_ = WEXITSTATUS(status); |
| 1607 | } else { |
| 1608 | retcode_ = 255; |
| 1609 | } |
| 1610 | return retcode_; |
| 1611 | } |
| 1612 | |
| 1613 | if (ret == -1) { |
| 1614 | // From subprocess.py |
| 1615 | // This happens if SIGCHLD is set to be ignored |
| 1616 | // or waiting for child process has otherwise been disabled |
| 1617 | // for our process. This child is dead, we cannot get the |
| 1618 | // status. |
| 1619 | if (errno == ECHILD) retcode_ = 0; |
| 1620 | else throw OSError("waitpid failed", errno); |
| 1621 | } else { |
| 1622 | retcode_ = ret; |
| 1623 | } |
| 1624 | |
| 1625 | return retcode_; |
| 1626 | #endif |
| 1627 | } |
| 1628 | |
| 1629 | inline void Popen::kill(int sig_num) |
| 1630 | { |