Simple bash script to kill stalled application

Sometimes, your application was stalled and stay in memory and never exit. For this, you can create a simple bash script to define whether the application is worth to be killed. This example will kill wkhtmltopdf-amd application that has state Sl and have been running for more than 1 hour. You can then call this script via cron, to call it periodically.
#!/bin/bash
get_proc=`ps -C wkhtmltopdf-amd -o pid=,stat=,etime= | awk '{if ($2 == "Sl" && !(substr($3,0,2)+0 < 1) ) print $1; }'`
for i in $get_proc
do
 kill -9 $i
done

Comments

Popular Posts