Kill idle Process using a script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Kill idle Process using a script
# 1  
Old 03-22-2013
Question Kill idle Process using a script

Hi,
I need a script that can automatically kill all processes named "webrepn" and "webrebw" if idle for more than 30 minutes.

Then I will have a Cron Job to run the script every night or 2-3 times a day depends on how this script helps.

Right now, I run "ps -ef | grep webrebn" and "kill -9 PID" to kill the idle processes using PID if I see any. Then repeat for "webrepw". The problem is if I forget to do so for couple days, my system will be very slow.
Would anybody help me out here?

I am using DB2 database in AIX 5.3 server.

Any help will be greatly appreciated.

Thank you,
Maggie
# 2  
Old 03-22-2013
How do you detect the processes are "idle" when you view the ps -ef output by eye?
# 3  
Old 03-22-2013
I will get this using ps -ef :
UID PID PPID C STIME TTY TIME CMD

if the stime was like two days or older, or I got a big time, like 122:57, I know it has been idle for a long time, longer than 30 mins.
# 4  
Old 03-23-2013
I would not necessarily call a process with high TIME values "idle".
# 5  
Old 03-23-2013
If you want to kill suspect_process if TIME > 30 minutes, I would do the following:
Code:
line=`ps -ef | grep suspect_process | grep -v grep`
pid=`echo $line | cut -f 2 -d " "`
minutes=`echo $line | cut -f 7 -d " " | cut -f 2 -d :`
if [ $minutes -gt 30 ]; then
  kill -9 $pid
  # Record what happened to log file
fi

I don't have the scenario to test this correctly.

TIME on my computer is like 00:00:00 - I cut the middle columns assuming that's the minutes.

STIME would be more awkward to use. On my computer it says something like Mar22. You could certainly use that kind of data, but it's going to be awkward dealing with new month, etc.

If the process is idle, why does it make the computer slow?
# 6  
Old 03-25-2013
Kill idle Process using a script

I should not use the word "IDLE" then. Normally, our online reports have 30 min time out. However, if the user closed/exit our online report menu improperly, then the process will still running for days even weeks. When more and more of this kind of processes running, our system will slow down.

If I run "ps auxw | grep webrepn", I get this:
Code:
USER         PID %CPU %MEM   SZ  RSS    TTY STAT    STIME  TIME COMMAND
userau    307408 13.9  0.0 3256 3200      - A    06:02:22 145:06 fglrun webrepn
userau    499886 11.5  0.0 3256 3200      - A    07:23:58 101:33 fglrun webrepn
userau    610386 11.3  0.0 3256 3200      - A    08:17:22 87:09 fglrun webrepn

Look at under %CPU, 10% for each one, it really will slow down the system.

So two things I need here, 1) to find out the pid of those process, 2) kill them.

Any thoughts?

Last edited by Franklin52; 03-26-2013 at 04:03 AM.. Reason: Please use code tags for data and code samples
# 7  
Old 03-25-2013
Code:
pgrep fglrun

?
Code:
pkill fglrun

?

Last edited by RudiC; 03-25-2013 at 07:13 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Idle command to kill the process running n unx box machine

Hi Team , I have one process named as cec_analysiseool that is running on unix box machine now i want to kill this process so please advise what will be the ideal command to kill this , what i have tried is :confused: kill -9 `ps -ef | grep cec_analysiseool | grep -v grep | awk '{print $2}'` (2 Replies)
Discussion started by: unclesamm
2 Replies

2. Solaris

Kill idle dt session

Hi, i need to kill the idle dt sessions through script, can anyone tell me how to do? RJS (2 Replies)
Discussion started by: rajasekg
2 Replies

3. UNIX for Dummies Questions & Answers

Script to start background process and then kill process

What I need to learn is how to use a script that launches background processes, and then kills those processes as needed. The script successfully launches the script. But how do I check to see if the job exists before I kill it? I know my problem is mostly failure to understand parameter... (4 Replies)
Discussion started by: holocene
4 Replies

4. Shell Programming and Scripting

Kill idle script is killing unnecessarly

Hi All,I have a problem with my kill idle script.my script is supposed to kill the user sessions which are idle for more than 2 hours.But is is killing the sessions which are idle for less than 2 hrs also.I dont know the exact time after which the script is killing,but it is less than 2 hours i am... (3 Replies)
Discussion started by: prabhu_kumar
3 Replies

5. Shell Programming and Scripting

Shell Script to Kill Process(number of process) Unix/Solaris

Hi Experts, we do have a shell script for Unix Solaris, which will kill all the process manullay, it used to work in my previous env, but now it is throwing this error.. could some one please help me to resolve it This is how we execute the script (and this is the requirement) ... (2 Replies)
Discussion started by: jonnyvic
2 Replies

6. AIX

Kill IDLE Process using script !!!

Dear Friends , I am using DB2 database in AIX 5.3 server . In my server some IDLE process are generated after several times which I need to kill it manually each and every time . The process I query like following : root@bagpuss $ ps auxw|sort -r +3|head -10 USER PID %CPU %MEM ... (3 Replies)
Discussion started by: shipon_97
3 Replies

7. Shell Programming and Scripting

How to kill process after x idle min?

I need a script to kill those process id whose idle time is more than 30min plz help me (3 Replies)
Discussion started by: salil2012
3 Replies

8. HP-UX

kill idle users

Hi, In my network we uses the NetTerm program to connect us to HP-UX 10.x server from windows workstations, but in some cases the user doesn't logout and close it by window's x button. The problem is that in HP-UX the user and all his tasks remain active and when he enter again HP-UX creates a... (12 Replies)
Discussion started by: efrenba
12 Replies

9. HP-UX

Is there a script available to kill Idle users

My max user parm is set to 1050. I'm currently at 1038 this is causing major slow downs on the server. I looking for a way log off "idle" user logins with out having to do it individually. :confused: (5 Replies)
Discussion started by: rfmurphy_6
5 Replies

10. SCO

Identifiy and Kill Idle Unix(SCO) Process called externally

Hi, Please let us know of any possiblity of identifying and killing unix proces invoked externally (by an external tool which does not create a session). 'who' command gives idle time of sessions. But what we are looking for is idle time of a process. 'ps' command gives the elapsed/running... (1 Reply)
Discussion started by: vbalajis
1 Replies
Login or Register to Ask a Question