#!/bin/bash var0=0 LIMIT=50 PROG="test" function kill_all { pids=`ps -ejH | grep ${PROG} | awk '{print $1}'` for p in ${pids} do echo ${p} if [ -n "${p}" ] then kill -9 ${p} fi done } function fail { echo "$@" kill_all exit 1 } while [ "$var0" -lt "$LIMIT" ] do kill_all setsid ./${PROG}& PID=${!} sleep 1 ./crtools exec -t ${PID} close 0 || fail "Failed to exec close 0" var0=`expr $var0 + 1` done echo "end" exit 0