1f08c3bdfSopenharmony_ci#!/bin/sh 2f08c3bdfSopenharmony_ci# SPDX-License-Identifier: GPL-2.0-or-later 3f08c3bdfSopenharmony_ci# Copyright (c) 2022 SUSE LLC <mdoucha@suse.cz> 4f08c3bdfSopenharmony_ci 5f08c3bdfSopenharmony_ciTMPFILE="/tmp/ltp_children_cleanup_$$.log" 6f08c3bdfSopenharmony_ci./test_children_cleanup 1>$TMPFILE 2>&1 7f08c3bdfSopenharmony_ciCHILD_PID=`sed -n 's/^.*Forked child \([0-9]*\)$/\1/p' "$TMPFILE"` 8f08c3bdfSopenharmony_cirm "$TMPFILE" 9f08c3bdfSopenharmony_ci 10f08c3bdfSopenharmony_ciif [ "x$CHILD_PID" = "x" ]; then 11f08c3bdfSopenharmony_ci echo "TFAIL: Child process was not created" 12f08c3bdfSopenharmony_ci exit 1 13f08c3bdfSopenharmony_cifi 14f08c3bdfSopenharmony_ci 15f08c3bdfSopenharmony_ci# The child process can stay alive for a short while even after receiving 16f08c3bdfSopenharmony_ci# SIGKILL, especially if the system is under heavy load. Wait up to 5 seconds 17f08c3bdfSopenharmony_ci# for it to fully exit. 18f08c3bdfSopenharmony_cifor i in `seq 6`; do 19f08c3bdfSopenharmony_ci CHILD_STATE=`sed -ne 's/^State:\s*\([A-Z]\).*$/\1/p' "/proc/$CHILD_PID/status" 2>/dev/null` 20f08c3bdfSopenharmony_ci 21f08c3bdfSopenharmony_ci if [ ! -e "/proc/$CHILD_PID" ] || [ "$CHILD_STATE" = "Z" ]; then 22f08c3bdfSopenharmony_ci echo "TPASS: Child process was cleaned up" 23f08c3bdfSopenharmony_ci exit 0 24f08c3bdfSopenharmony_ci fi 25f08c3bdfSopenharmony_ci 26f08c3bdfSopenharmony_ci sleep 1 27f08c3bdfSopenharmony_cidone 28f08c3bdfSopenharmony_ci 29f08c3bdfSopenharmony_ciecho "TFAIL: Child process was left behind" 30f08c3bdfSopenharmony_ciexit 1 31