MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / lwp_waitpid

Function lwp_waitpid

components/lwp/lwp_pid.c:1578–1650  ·  view source on GitHub ↗

* @brief Wait for process termination and return status * * @param[in] pid Process ID to wait for: * >0 - specific child process * -1 - any child process * -pgid - any child in process group * 0 - any child in caller's process group * @param[out] status Pointer to store child exit status (optional) * @param[in] options Wait option

Source from the content-addressed store, hash-verified

1576 * - Process group wait (pid == 0 or pid < -1)
1577 */
1578pid_t lwp_waitpid(const pid_t pid, int *status, int options, struct rusage *ru)
1579{
1580 pid_t rc = -1;
1581 struct rt_thread *cur_thr;
1582 struct rt_lwp *self_lwp;
1583
1584 cur_thr = rt_thread_self();
1585 self_lwp = lwp_self();
1586
1587 if (!cur_thr || !self_lwp)
1588 {
1589 rc = -EINVAL;
1590 }
1591 else
1592 {
1593 /* check if able to reap desired child immediately */
1594 if (pid > 0)
1595 {
1596 /* if pid is child then try to reap it */
1597 rc = _verify_child_and_reap(cur_thr, self_lwp, pid, options, status, ru);
1598 }
1599 else if (pid == -1)
1600 {
1601 /* any terminated child */
1602 rc = _reap_any_child_pid(cur_thr, self_lwp, 0, options, status, ru);
1603 }
1604 else
1605 {
1606 /**
1607 * (pid < -1 || pid == 0)
1608 * any terminated child with matched pgid
1609 */
1610
1611 pid_t pair_pgid;
1612 if (pid == 0)
1613 {
1614 pair_pgid = lwp_pgid_get_byprocess(self_lwp);
1615 }
1616 else
1617 {
1618 pair_pgid = -pid;
1619 }
1620 rc = _reap_any_child_pid(cur_thr, self_lwp, pair_pgid, options, status, ru);
1621 }
1622
1623 if (rc == HAS_CHILD_BUT_NO_EVT)
1624 {
1625 if (!(options & WNOHANG))
1626 {
1627 /* otherwise, arrange a suspend and wait for async event */
1628 options |= WEXITED;
1629 rc = _wait_and_reap(cur_thr, self_lwp, pid, options, status, ru);
1630 }
1631 else
1632 {
1633 /**
1634 * POSIX.1: If waitpid() was invoked with WNOHANG set in options,
1635 * it has at least one child process specified by pid for which

Callers 3

waitpidFunction · 0.85
sys_waitpidFunction · 0.85
sys_wait4Function · 0.85

Calls 6

rt_thread_selfFunction · 0.85
lwp_selfFunction · 0.85
_verify_child_and_reapFunction · 0.85
_reap_any_child_pidFunction · 0.85
lwp_pgid_get_byprocessFunction · 0.85
_wait_and_reapFunction · 0.85

Tested by

no test coverage detected