#!/bin/sh

TRIES=10

for ((a = 1 ; a <= $TRIES ; a++))
do
    cat /dev/zero >/dev/null &
    CAT_PID=$!

    echo "tracee started with PID $CAT_PID"

    strace -p $CAT_PID 2>/dev/null &
    STRACE_PID=$!

    echo "tracer started with PID $STRACE_PID"

    sleep 0.1
    kill -9 $STRACE_PID
    wait $STRACE_PID

    FAILED=0
    if ! kill -9 $CAT_PID
    then
        echo "*** ERROR *** Tracee disappeared mysteriously"
	FAILED=1
    fi

    wait $CAT_PID
    CAT_STATUS=$?
    if [ "$CAT_STATUS" -ne 137 ]	# 128 + 9 means killed with SIGKILL
    then
	echo "*** WARNING *** Tracee exited with status $CAT_STATUS"
    fi
    if [ "$FAILED" -ne 0 ]
    then
	exit $FAILED
    fi
done

echo "The bug was not reproduced after $TRIES tries"
exit 0
