The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Check the process before run or not mr_bold UNIX for Dummies Questions & Answers 3 05-23-2007 03:25 AM
Check process in AIX lweegp UNIX for Dummies Questions & Answers 2 03-13-2006 08:31 PM
Check the process ust UNIX for Dummies Questions & Answers 1 03-01-2006 07:44 AM
Check the process ust UNIX for Advanced & Expert Users 2 09-27-2005 08:16 AM
process check k@ssidy UNIX for Dummies Questions & Answers 13 06-17-2005 12:43 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 09-17-2005
ust ust is offline
Registered User
 

Join Date: Feb 2005
Posts: 95
check the process

how to kill the process that are idle over 30 minutes ? thx
Reply With Quote
Forum Sponsor
  #2  
Old 09-21-2005
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,699
Here is something that I wrote to identify whether a process has been idle for over 30 mins.

Assumptions. The process is attached to a tty.

There are some processes which might be over 30 mins, and are idle. But you need to take precaution when using this script. Some of them might be very useful even though they are/have been idle for days.

Provide a pid when running the script.

Code:
#! /bin/ksh
# idle.ksh
# Find the idle time of a process.
#
# Assumptions:
# Process is attached to a tty.
#

[[ -z "$1" ]] && echo "Usage: $0 pid" && exit 1

[[ "$1" != +([0-9]) ]] && echo "$1 is not a valid pid" && exit 1

PID="$1"
W=$(which w)
PS=$(which ps)
SED=$(which sed)
AWK=$(which awk)

TTY=$($PS -o tty4 $PID)
TTNo=$(echo "$TTY" | $SED -e '/TTY/d')

TIME=$($W | $SED -n -e "/pts\/$TTNo/p" |  $AWK '{ print $5 }')

echo $PID has been idle for $TIME

[[ $TIME = *day* ]] && echo "Killing $PID" && kill -9 $PID && exit 0

IDLE=${TIME%%:*}

[[ $IDLE -gt 30 ]] && echo "Killing $PID" && kill -9 $PID && exit 0
Vino

Last edited by vino; 09-21-2005 at 11:34 PM.
Reply With Quote
  #3  
Old 02-02-2006
Registered User
 

Join Date: Jan 2005
Posts: 682
Deleted, wrong post.

Last edited by tmarikle; 02-02-2006 at 11:09 AM. Reason: Commented on incorrect post
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 05:07 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0