From d5c4433a019e267feaf13b9f2282b8ecc1f3ecda Mon Sep 17 00:00:00 2001 From: yushuailong Date: Sat, 26 Sep 2026 10:52:45 +0800 Subject: [PATCH] sched/waitpid: Preserve child status with WNOWAIT. When waitpid(-1) finds an exited child in the retained status list, honor WNOWAIT instead of unconditionally removing and freeing the child entry. This makes the any-child path consistent with the specific-PID and SIGCHLD paths. Assisted-by: OpenAI Codex Signed-off-by: yushuailong --- sched/sched/sched_waitpid.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/sched/sched/sched_waitpid.c b/sched/sched/sched_waitpid.c index 25e326c36f1..484a2ce3307 100644 --- a/sched/sched/sched_waitpid.c +++ b/sched/sched/sched_waitpid.c @@ -93,10 +93,14 @@ int waittcb(FAR struct tcb_s *rtcb, pid_t pid, int options, ret = child->ch_pid; - /* Discard the child entry and break out of the loop */ + /* Discard the child entry unless WNOWAIT is set */ + + if ((options & WNOWAIT) == 0) + { + group_remove_child(rtcb->group, child->ch_pid); + group_free_child(child); + } - group_remove_child(rtcb->group, child->ch_pid); - group_free_child(child); break; } }