[LTP] [RFC] Shell API timeout sleep orphan processes

Joerg Vehlow lkml@jv-coder.de
Fri May 7 06:48:35 CEST 2021


Hi Li,

> (Sorry for the late reply, I was just back from the Holidays)
>
> Before we decide to rewrite in C, can we think about this below method?
>
> --- a/testcases/lib/tst_test.sh
> +++ b/testcases/lib/tst_test.sh
> @@ -26,7 +26,7 @@ trap "tst_brk TBROK 'test interrupted or timed out'" INT
>   _tst_cleanup_timer()
>   {
>          if [ -n "$_tst_setup_timer_pid" ]; then
> -               kill $_tst_setup_timer_pid 2>/dev/null
> +               kill -TERM $_tst_setup_timer_pid 2>/dev/null
>                  wait $_tst_setup_timer_pid 2>/dev/null
>          fi
>   }
> @@ -486,7 +486,7 @@ _tst_setup_timer()
>          tst_res TINFO "timeout per run is ${h}h ${m}m ${s}s"
>
>          _tst_cleanup_timer
> -       sleep $sec && _tst_kill_test &
> +       (trap 'kill $!; exit' TERM; sleep $sec & wait $! && _tst_kill_test)&
>
>          _tst_setup_timer_pid=$!
>   }
Thanks, good idea. This looks like it works. My tests are passing. I 
will test this a bit more.
Although I already submitted a rewrite in c, I would prefer this 
solution, maybe with a bit improved readability.
I will post a new patch when I finished testing later today.

Jörg


More information about the ltp mailing list