Operating System - HP-UX
1752777 Members
6629 Online
108789 Solutions
New Discussion юеВ

script that kills ghost processes

 
p7
Frequent Advisor

script that kills ghost processes

hi all

we have a system thats been running acucobol and oracle for about 7 yrs. sometimes when the users get ancy they shutdown their pcs and leave ghosts running taking cpu time. we have this script that runs and kills them, but i noticed that the first part(processlist, userlist) doesnt work, the second part does.


any ideas?

thx in advance

# The purpose of this script is to clean up orphan processes.
# Exclusions are implemented by the "grep -v" command.
#
set -o xtrace
date
cd /util

# This loop generates a list of users, then generates a list of processes
# associated with each users id. If the terminal is a "?" it kills them.

#USERLIST
for user in `/usr/bin/ps -ft? | /usr/bin/grep "\-sh" | \
/usr/bin/grep -v root |/usr/bin/grep -v oracle|/usr/bin/grep -v ora
_|/usr/bin/grep -v ftpmat |/usr/bin/grep -v ftplaw|/usr/bin/grep -v lawcron|/usr
/bin/grep -v snamat|awk '{print $1}`
do
#PROCESSLIST
/usr/bin/ps -fu $user | /usr/bin/grep -v PID | \
/usr/bin/awk '{if ($6 == "?") {print $2}}' | \
/usr/bin/xargs -n1 kill 2>>/dev/null
done

# This loop picks up child processes that have that have lost their parent
# user processes. It is repeated for throughness.

for proc in `ps -ft "?" | grep -v ftpmat |grep -v root|grep -v oracle|grep -v or
a_| grep -v snamat | grep -v lawcron | grep -v fptlaw | grep -e runwcis -e runcm
s -e runplis -e runctms | awk '{print $2}'`
do
ps -ef | grep " "$proc" " | grep -v grep | awk '{print $2}' | \
sort -r | xargs -n 1 kill
done

sleep 5

for proc in `ps -ft "?" | grep -v ftpmat |grep -v root|grep -v oracle|grep -v or
a_| grep -v snamat | grep -v lawcron | grep -v ftplaw | grep -e runwcis -e runcm
s -e runplis -e runctms | awk '{print $2}'`
do
ps -ef | grep " "$proc" " | grep -v grep | awk '{print $2}' | \
sort -r | xargs -n 1 kill

4 REPLIES 4
Steven E. Protter
Exalted Contributor

Re: script that kills ghost processes

We have a similar issue with our Software AG users.

The close the app instead of logging out and the process remains for 30 minutes until timeout.

You are moving in the right direction, but take care to distinguish live oracle sessions from orphan ones.

User training can help with this too.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
harry d brown jr
Honored Contributor

Re: script that kills ghost processes


Aren't ghosts already dead? It's like Night of the Living Dead - You kill them and they just keep coming back.

My idea, and it worked in a lot of banks: remove the users keyboard and make them sign it back out from the VP. See how long it takes them to remember to gracefully shutdown their applications!!!

live free or die
harry d brown jr
Live Free or Die
p7
Frequent Advisor

Re: script that kills ghost processes

yea i know, but they wont listen!

any other ideas, thx
Fred Ruffet
Honored Contributor

Re: script that kills ghost processes

If I understand what you want : all processes owned by a user who has a -sh running with no terminal. Then this one seems to work :

----- starts code
for user in `/usr/bin/ps -ft? | \
/usr/bin/grep "\-sh" | \
/usr/bin/grep -v root | \
/usr/bin/grep -v oracle | \
/usr/bin/grep -v ora_ | \
/usr/bin/grep -v ftpmat | \
/usr/bin/grep -v ftplaw | \
/usr/bin/grep -v lawcron | \
/usr/bin/grep -v snamat | \
awk '{print $1}'`
do
/usr/bin/ps -ft? -u $user | /usr/bin/grep -v PID | /usr/bin/awk '{print $2}' | /usr/bin/xargs kill
done
----- ends code

Some few points to discuss :
. If a user have two sessions and one has no terminal, your procedure will kill his two sessions
. there's a missing ' before the last ` but it doesn't seem to be a problem :)

Regards,

Fred
--

"Reality is just a point of view." (P. K. D.)