[LTP] [PATCH] Terminate leftover subprocesses when main test process crashes

Martin Doucha mdoucha@suse.cz
Fri Feb 11 10:17:31 CET 2022


On 11. 02. 22 7:47, Li Wang wrote:
> On Fri, Feb 11, 2022 at 12:18 AM Martin Doucha <mdoucha@suse.cz
> <mailto:mdoucha@suse.cz>> wrote:
>     @@ -1560,6 +1568,7 @@ void tst_run_tcases(int argc, char *argv[],
>     struct tst_test *self)
> 
>             SAFE_SIGNAL(SIGALRM, alarm_handler);
>             SAFE_SIGNAL(SIGUSR1, heartbeat_handler);
>     +       SAFE_SIGNAL(SIGCHLD, sigchild_handler);
> 
> 
> Do we really need setup this signal handler for SIGCHILD?
> 
> Since we have already called 'SAFE_WAITPID(test_pid, &status, 0)'
> in the library process (lib_pid) which rely on SIGCHILD as well.
> And even this handler will be called everytime when test exit normally.
> 
> Maybe better just add a kill function to cleanup the remain
> descendants if main test process exit with abonormal status.
> 
> e.g.
> 
> --- a/lib/tst_test.c
> +++ b/lib/tst_test.c
> @@ -1503,6 +1503,8 @@ static int fork_testrun(void)
>         if (WIFEXITED(status) && WEXITSTATUS(status))
>                 return WEXITSTATUS(status);
>  
> +       kill(-test_pid, SIGKILL);

This will not work because at this point, the child process was already
destroyed by waitpid() and all its remaining children were moved under
PID 1 (init). The only place where the grandchildren are still reachable
this way is in SIGCHLD handler while the dead child process still exists
in zombie state.

-- 
Martin Doucha   mdoucha@suse.cz
QA Engineer for Software Maintenance
SUSE LINUX, s.r.o.
CORSO IIa
Krizikova 148/34
186 00 Prague 8
Czech Republic


More information about the ltp mailing list