I wrote this today to kill orphan processes left by my very dirty chk_servs.ksh script that runs constantly in a VNC session using ssh-agent to ensure encrypted traffic. These orphaned procs were eating up my CPU.
# This script kills orphan processes for a particular user if [[ $# < 1 || $# > 1 ]];then echo "Syntax : kill_orphans.ksh" exit 1 fi user=$1 cat /etc/passwd | awk -F : '{print $1}' | grep $user >/dev/null rc=$? if [[ $rc > 0 ]];then echo "$user is not a valid user." exit 2 fi ps -fu $user | awk '{print $3,$2}' | while read ppid pid do if [[ $ppid -eq 1 ]];then echo "Killing orphan process $pid..." kill $pid fi done exit 0 |