finding idle time of a process

Matez,

I have a list of process id's in a text file. I want to know how to find the idle time of a process which are more than 300secs and kill them accordingly.

Could you please help me to get these details. I want to write a shell script with this.

Thanks..Krish :slight_smile:

See the script in check the process

Matez,

I have a list of process id's in a text file. I want to know how to find the idle time of a process which are more than 300secs and kill them accordingly.

Could you please help me to get these details. I want to write a shell script with this.

Thanks..Krish

Vino,

Thank you very much for your help man...could you please explain me the below..

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 }')

thanks..krish

when i executing i get the below error. mine is a HP UX box.

crypto $ ./process.sh 4722
/bin/ps: illegal option -- o
usage: /bin/ps [-edaxzflP] [-u ulist] [-g glist] [-p plist] [-t tlist] [-R prmgroup] [-Z psetidlist]
4722 has been idle for -n
./process.sh[28]: -n: bad number

Please dont duplicate your posts. Merging the other thread.

am sorry will delete that..can you help me with this..

I dont have an HP UX box with me to crosscheck. See if you have any other ps version's installed on your box. And see if it has the -o flag supported.

Nope it doesn't support -o option..nyother way...

TTY=$($PS -o tty4 -o $PID)

could you please let me know what does the -o option does there so that i can find any equallant option available in HP-Ux

aju thnx for your post actually -o option is not there in HP-UX at all...

i think i have to use this is that right..

                    The controlling terminal for the process.  The

tty : default heading for this column is TT if -o is
specified and TTY otherwise.

i got it buddies thnx....it shoud be like this

TTY=$($PS tty4 -o $PID)

no -o after ps and now if i execute the script it says like this.

crypto $ ./process.sh 4722
sed: /pts\/ 4560 pts/0 0:00 bksm is not a recognized function.
4722 has been idle for

could u pls check vino.

here s the complete output of the script.

crypto $ sh -x process.sh 4722
+ set -o vi
+ alias h=history 23
+ alias rm=rm -i
+ alias cp=cp -i
+ alias mv=mv -i
+ alias l=ls -m
+ alias ll=ls -l
+ alias lsf=ls -F
+ [[ -z 4722 ]]
+ [[ 4722 != +([0-9]) ]]
+ PID=4722
+ + which w
W=/bin/w
+ + which ps
PS=/bin/ps
+ + which sed
SED=/bin/sed
+ + which awk
AWK=/bin/awk
+ + /bin/ps tty4 -o 4722
TTY= PID TTY TIME COMMAND
7016 pts/0 0:00 ps
4560 pts/0 0:00 bksm
4570 pts/0 0:00 ksh
7007 pts/0 0:00 sh
+ + /bin/sed -e /TTY/d
+ echo PID TTY TIME COMMAND
7016 pts/0 0:00 ps
4560 pts/0 0:00 bksm
4570 pts/0 0:00 ksh
7007 pts/0 0:00 sh
TTNo= 7016 pts/0 0:00 ps
4560 pts/0 0:00 bksm
4570 pts/0 0:00 ksh
7007 pts/0 0:00 sh
+ + /bin/w
+ /bin/awk { print $5 }
+ /bin/sed -n -e /pts\/ 7016 pts/0 0:00 ps
4560 pts/0 0:00 bksm
4570 pts/0 0:00 ksh
7007 pts/0 0:00 sh/p
sed: /pts\/ 7016 pts/0 0:00 ps is not a recognized function.
TIME=
+ echo 4722 has been idle for
4722 has been idle for
+ [[ = *day* ]]
+ IDLE=
+ [[ -gt 30 ]]
[1] + Done sh kri1.sh&

Actually, yes it is. Read the man page. And see this thread.

Thatz fine...i fixed that one already reading the man page...as per man page if -o is specified it should be tty else tt am i right

TT=$($PS -o tty4 $PID)

but itz giving a error ps is not a function i dunno why..can u help in that...am not tht much familiar with shell scripts..just started writing guyz..so please help me guru's..thnx..

can smebody help 2 me..on this...cmon guru's plz help this poor chap..

chk your sed command, in this u forgot to put / at end

why don't you hire a UNIX admin, and stop double-posting, using "cyber-chat" phrases ?