<div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-size:small"><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Feb 11, 2022 at 6:34 PM Li Wang <<a href="mailto:liwang@redhat.com">liwang@redhat.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div style="font-size:small"><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Feb 11, 2022 at 5:17 PM Martin Doucha <<a href="mailto:mdoucha@suse.cz" target="_blank">mdoucha@suse.cz</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 11. 02. 22 7:47, Li Wang wrote:<br>
> On Fri, Feb 11, 2022 at 12:18 AM Martin Doucha <<a href="mailto:mdoucha@suse.cz" target="_blank">mdoucha@suse.cz</a><br>
> <mailto:<a href="mailto:mdoucha@suse.cz" target="_blank">mdoucha@suse.cz</a>>> wrote:<br>
>     @@ -1560,6 +1568,7 @@ void tst_run_tcases(int argc, char *argv[],<br>
>     struct tst_test *self)<br>
> <br>
>             SAFE_SIGNAL(SIGALRM, alarm_handler);<br>
>             SAFE_SIGNAL(SIGUSR1, heartbeat_handler);<br>
>     +       SAFE_SIGNAL(SIGCHLD, sigchild_handler);<br>
> <br>
> <br>
> Do we really need setup this signal handler for SIGCHILD?<br>
> <br>
> Since we have already called 'SAFE_WAITPID(test_pid, &status, 0)'<br>
> in the library process (lib_pid) which rely on SIGCHILD as well.<br>
> And even this handler will be called everytime when test exit normally.<br>
> <br>
> Maybe better just add a kill function to cleanup the remain<br>
> descendants if main test process exit with abonormal status.<br>
> <br>
> e.g.<br>
> <br>
> --- a/lib/tst_test.c<br>
> +++ b/lib/tst_test.c<br>
> @@ -1503,6 +1503,8 @@ static int fork_testrun(void)<br>
>         if (WIFEXITED(status) && WEXITSTATUS(status))<br>
>                 return WEXITSTATUS(status);<br>
>  <br>
> +       kill(-test_pid, SIGKILL);<br>
<br>
This will not work because at this point, the child process was already<br>
destroyed by waitpid() and all its remaining children were moved under</blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
PID 1 (init). The only place where the grandchildren are still reachable<br>
this way is in SIGCHLD handler while the dead child process still exists<br>
in zombie state.</blockquote><div><br></div><div><div style="font-size:small">Signal communicatoin is asynchronous processing, setup SIGCHILD</div><div>handler can not 100% garantee the libarary process response</div><div style="font-size:small">in time as well.</div><br></div><div><div style="font-size:small">Though the test_pid being moved under PID 1(init), kill(-test_pid, SIGKILL)</div><div style="font-size:small">still works well for killing them. That beacuse the dead child process still</div><div style="font-size:small">exists until kernel recliam its all parent.</div></div></div></div></blockquote><div><br></div><div><br></div><div><div class="gmail_default" style="font-size:small">I give 5 seconds sleep before sending SIGKILL in lib-process</div><div class="gmail_default" style="font-size:small">and modified the test_children_cleanup.c to print ppid each 1sec</div><div class="gmail_default" style="font-size:small">to verify this:</div></div><div><br></div><div class="gmail_default" style="font-size:small"># ./test_children_cleanup</div>tst_test.c:1452: TINFO: Timeout per run is 0h 00m 10s<br>test_children_cleanup.c:20: TINFO: Main process 173236 starting<br>test_children_cleanup.c:39: TINFO: Forked child 173238<br>test_children_cleanup.c:33: TINFO: ppid is 173236<br>test_children_cleanup.c:33: TINFO: ppid is 1<br>test_children_cleanup.c:33: TINFO: ppid is 1<br>test_children_cleanup.c:33: TINFO: ppid is 1<br>test_children_cleanup.c:33: TINFO: ppid is 1<br>tst_test.c:1502: TINFO: If you are running on slow machine, try exporting LTP_TIMEOUT_MUL > 1<br>tst_test.c:1504: TBROK: Test killed! (timeout?)<br><br>Summary:<br>passed   0<br>failed   0<br>broken   1<br>skipped  0<br>warnings 0<br><div class="gmail_default" style="font-size:small"></div></div><div class="gmail_default" style="font-size:small">=======</div><div class="gmail_default" style="font-size:small"><br></div>--- a/lib/newlib_tests/test_children_cleanup.c<br>+++ b/lib/newlib_tests/test_children_cleanup.c<br>@@ -28,7 +28,11 @@ static void run(void)<br> <br>        /* Start child that will outlive the main test process */<br>        if (!child_pid) {<br>-               sleep(30);<br>+               int i;<br>+               for (i = 0; i < 30; i++) {<br>+                       tst_res(TINFO, "ppid is %d", getppid());<br>+                       sleep(1);<br>+               }<br>                return;<br>        }<br> <br>diff --git a/lib/tst_test.c b/lib/tst_test.c<br>index 84ce0a5d3..6f2d93611 100644<br>--- a/lib/tst_test.c<br>+++ b/lib/tst_test.c<br>@@ -1503,6 +1503,9 @@ static int fork_testrun(void)<br>        if (WIFEXITED(status) && WEXITSTATUS(status))<br>                return WEXITSTATUS(status);<br> <br>+       sleep(5);<br>+       kill(-test_pid, SIGKILL);<br>+<br>        if (WIFSIGNALED(status) && WTERMSIG(status) == SIGKILL) {<br>                tst_res(TINFO, "If you are running on slow machine, "<br>                               "try exporting LTP_TIMEOUT_MUL > 1");<br><div class="gmail_default" style="font-size:small"><br></div><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div>Regards,<br></div><div>Li Wang<br></div></div></div></div>