Script to kill stranded/orphan process by users.

I have customers on our AIX/UNIX node startup a process that becomes stranded or orphaned and must be killed. I would like to create a script to check for these orphan processes and kill them. I can have cron run this job. The customers process will run and after 24 hours time out leaving an orphan process. I would like to have the script kill them after 24 hours. Thanks in advance for any help you can provide.

rjohnson :frowning:

By orphan, do you mean zombies? If so, you can't kill them.
If they're simply going to run forever, you might look into something like idled:
http://www.darkwing.com/idled/

Hope this help, and please search the forums for more information.

You have to know your applications fairly well to do this automated.
We are on digital unix.
Do you have a common parent process that launches the child processes that you want to kill ??
We have "captive" users that log in through a main menu script. If you have something like this, you can use ps -ef to grep for processes where initial login parent script is gone.
Many times our processes end up reverting to uid 1 under root and that makes it very easy to cleanup by grepping on the known process name and checking to see if the parent is uid one. (when it shouldnt be uid 1)
Hope this helps.

I do a ps -ef|grep on the program name and then I use the kill command on the parent process id. I only kill the ones that go from a time only stamp to a date stamp like Mar 6. I do this daily and over the weekend I have about 25 processes to kill on Monday. I will look into IDLE and see if this is an option. Thanks for your help.

This is one of my scripts.....

#! /bin/sh
KILLLOG=/tmp/killlogfor PID in `ps -ef | grep -v root | grep processname | awk '{print $2}'`
do
echo killing $PID
kill -9 $PID
done

This is another that also kills message queues:

for PID in `ps -ef | grep -v root | grep -v proccessname | grep -v userid | grep " 1 " | awk '{print $2}' `
do
echo killing $PID$TEST
kill $PID
for QID in `ipcs -qp | grep -w $PID | awk '{print $2}'`
do
echo removing $QID$TEST
ipcrm -q $QID
done

Hope this helps...