#!/bin/bash finds=0 while : do line=$(ps -el | tr -s " " | cut -d " " -f 2,4,14 | grep $1 | cut -d " " -f 1,2) if [[ $(echo $line | cut -d " " -f 1) = "Z" ]] then let finds++ if [[ $finds -ge 5 ]]; then pid=$(echo $line | cut -d " " -f 2) kill -9 $pid echo "Killed process $pid" exit 0 fi elif [[ $finds -ne 0 ]] then finds=0 fi sleep $2 done