![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
check the process
how to kill the process that are idle over 30 minutes ? thx
|
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
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
Last edited by vino; 09-21-2005 at 11:34 PM. |
|
#3
|
|||
|
|||
|
Deleted, wrong post.
Last edited by tmarikle; 02-02-2006 at 11:09 AM. Reason: Commented on incorrect post |
|||
| Google The UNIX and Linux Forums |