Re: [hackers] Re: [dwm][PATCH v2] Use sigaction(SA_NOCLDWAIT) for SIGCHLD handling

From: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
Date: Sat, 28 Jan 2023 12:53:48 +0100

On Sat, Jan 28, 2023 at 03:04:50PM +0600, NRK wrote:
> Hi Hiltjo,
>
> On Sat, Jan 28, 2023 at 12:11:44AM +0100, Hiltjo Posthuma wrote:
> > We do not need to waitpid() on child processes. It is handled already
> > by using sigaction().
>
> Here's a test case. I see `cat` turning into a zombie on my system
> without the `waitpid`:
>
> [/tmp]~> cat test.c
> #include <signal.h>
> #include <stdio.h>
> #include <stdlib.h>
> #include <sys/wait.h>
> #include <unistd.h>
>
> int main(void)
> {
> struct sigaction sa;
>
> puts("waiting for cat to become a zombie");
> sleep(1);
>
> sigemptyset(&sa.sa_mask);
> sa.sa_flags = SA_NOCLDSTOP | SA_NOCLDWAIT | SA_RESTART;
> sa.sa_handler = SIG_IGN;
> sigaction(SIGCHLD, &sa, NULL);
>
> puts("hello there");
> (void)getchar();
> }
> [/tmp]~> cat test.sh
> #!/bin/sh
>
> cat &
> exec ./test
> [/tmp]~> cc -o test test.c
> [/tmp]~> ./test.sh
> waiting for cat to become a zombie
> hello there
>
> Just putting `while (waitpid(-1, NULL, WNOHANG) > 0);` after the
> `sigaction` call (without worrying about EINTR) should still be better
> than not calling `waitpid` at all IMO.
>
> - NRK
>

Hi,

OK thanks, below is the final patch I intend to commit:
Received on Sat Jan 28 2023 - 12:53:48 CET

This archive was generated by hypermail 2.3.0 : Sat Jan 28 2023 - 13:00:33 CET