MCPcopy Create free account
hub / github.com/arun11299/cpp-subprocess / poll

Method poll

cpp-subprocess/subprocess.hpp:1579–1627  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1577}
1578
1579inline 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
1629inline void Popen::kill(int sig_num)
1630{

Callers 3

test_ret_codeFunction · 0.80
test_redirectFunction · 0.80
test_sleepFunction · 0.80

Calls 1

OSErrorClass · 0.85

Tested by 3

test_ret_codeFunction · 0.64
test_redirectFunction · 0.64
test_sleepFunction · 0.64