Re: [PATCH] selftests/proc: proc-empty-vm: wait for child's SIGSEGV instead of sleep(1)
From: Alexey Dobriyan
Date: Sun Nov 01 2026 - 07:57:47 EST
On Fri, Oct 23, 2026 at 07:34:33PM +0100, Drif Abdelmalek Mohamed Said wrote:
> The test had a TODO asking for a reliable way to know when the child's
> munmap() has finished, and used sleep(1) in the meantime.
>
> Unmapping the whole address space leaves the child with no code to run,
> so it segfaults. Since it is traced, the SIGSEGV stop is reported to
> the parent through waitpid(), which is exactly the signal the TODO
> wanted. Wait for it there and drop the sleep and the TODO.
>
> The stop is now consumed up front, so SIGKILL the child before the
> final reap.
OK I recall what's going on here.
The only thing to worry is child pid reuse but child is under ptrace
so it should be fine.
Reviewed-by: Alexey Dobriyan <adobriyan@xxxxxxxxx>
> + for (;;) {
> + p = waitpid(pid, &wstatus, 0);
> + if (p == -1 && errno == EINTR)
> + continue;
> + break;
> + }
do/while EINTR loops are shorter:
do {
rv = f();
} while (rv == -1 && errno == EINTR);