User Tools

Site Tools


aix:scripts_timeout

AIX script that kill a process after timeout

[root@aixsrv]/root# cat test_timeout.sh
#!/bin/ksh93

DURATION="1200"   # 20 minutes

timeout() {
#    to=$1; shift
    $@ & wp=$! start=0
     while kill -0 $wp; do
        read -t 1
        start=$((start+1))
        if [ $start -ge $DURATION ]; then
            kill -9 $wp && echo "Process killed after $DURATION seconds" && break
        fi
    done
}

timeout $@
aix/scripts_timeout.txt · Last modified: 2021/01/01 21:24 (external edit)