Operating System - HP-UX
1826899 Members
3224 Online
109705 Solutions
New Discussion

Re: Kill the dead processes

 
SOLVED
Go to solution
Leah Chow
Frequent Advisor

Kill the dead processes

Hello,

I have a question about how to kill the dead processes on my server.
My company uses an ERP software called Glovia and it only has 50 runtime user licenses.
When more than 50 users are logged in, it gives users trouble. I used 'ps -ef |grep glovia|more'
and found out that there are a lot dead processes still sitting there for more than or days. I killed all of those dead processes. Then the users can log in without problem.
I am wondering how I can write a shell script to do it. I want to kill the processs those belong to Glovia user are older than 1 day, since ps -ef only show the time not the date, could someone tell me how to write the script?

Really appreciate your help!

Leah
7 REPLIES 7
harry d brown jr
Honored Contributor

Re: Kill the dead processes

You really need the vendor to FIX the issue. It's not a good idea to be killing processes, because it could lead to data corruption.

You can write a script and put it into cron, but I again stress that the vendor needs to FIX their application.

live free or die
harry
Live Free or Die
Marvin Strong
Honored Contributor

Re: Kill the dead processes

The stime column of ps -ef should be the starting time, and if the process is over 24 hours old it should just show the date like: Jun 12 or whatever. If you are just seeing times as 08:35:45, those processes where started that day.

Kent Ostby
Honored Contributor
Solution

Re: Kill the dead processes

This will get you a list of processes that include glovia and are older then 24 hours old:

ps -ef | grep glovia | cut -c1-33 | awk 'NF>5'

This will also send the kill command assuming that useme exists (from a previous run) as executable:

ps -ef | grep kmo| cut -c1-33 | awk 'NF>5 {print "kill $2"}'> us
"kill $2"}'> useme; ./useme

"Well, actually, she is a rocket scientist" -- Steve Martin in "Roxanne"
Mark Greene_1
Honored Contributor

Re: Kill the dead processes

Try this:

#!/bin/ksh
_Month=`date +%b`
ps -ef |grep -v "root">/tmp/process.lst

for _Line in `cat /tmp/process.lst`; do
if [[ (echo $_Line|grep "$_Month") -ne "" ]]; then
echo $_Line|tr -s " "|cut -d" " -f3|xargs -i kill -9 {}`
fi
done


This will capture the PS output for all non-root proceses, look for the abbreviated month in the PS listing, extract the PID from that line, and pipe it to kill -9.

You can change the 'grep -v "root"' part to 'grep "userid"' where "userid" is the ID that runs the processes in question. What you want to avoid is automatically killing all your root owned processes and crashing your system.

HTH
mark
the future will be a lot like now, only later
Martin Johnson
Honored Contributor

Re: Kill the dead processes

I would use the "kill -15" instead of "-9" to give the process a chance to clean up. Of course if "-15", you can use "-9" as the last resort.

HTH
Marty
David Nixon
Valued Contributor

Re: Kill the dead processes

Hello Leah,
I adopted a 'C' program solution to
dealing with this sort of problem.
E.g. in your case I would have a daily
Cron job run my program as follows:

sig -r 96 TERM KILL

This would send the TERM KILL sequence
to all (backgrounded) instances of the named process over 4 days old..
If you want to try this approach instead of writing
a shell or Perl script , I could supply source.
Leah Chow
Frequent Advisor

Re: Kill the dead processes

Thank you very much for all of your help. I have already fixed this problem.

Leah