finding idle time of a process

sysgate am in a hurry thtz why asking help...if i am not n a hurry i dont hav any issues..so understand me...anyway thnx mates i will check everythng will get bck 2 u....

well, its to sound 'l33t' asking for help :stuck_out_tongue:

:d :d :d

Krrishv, we have some rules here and you have broken quite a few of them:
(3) Refrain from idle chatter that does not contribute to the knowledge base.
(4) Do not 'bump up' questions if they are not answered promptly. No duplicate or cross-posting and do not report a post where your goal is to get an answer more quickly.
(9) Edit your posts if you see spelling or grammar errors (don't write in cyberchat or cyberpunk style). English only.

Please review the rules and make sure that you follow them.

Sorry,will follow it up in future as i am new to this community.

please find my script execution. I am getting an error. Please help.

crypto $ sh kri1.sh &
[1] 17766
crypto $ sh -x proc.sh 17766
+ 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 17766 ]]
+ [[ 17766 != +([0-9]) ]]
+ PID=17766
+ + which w
W=/usr/bin/w
+ + which ps
PS=/usr/bin/ps
+ + which sed
SED=/usr/bin/sed
+ + which awk
AWK=/usr/bin/awk
+ + /usr/bin/ps -o tty4 17766
/usr/bin/ps: illegal option -- o
usage: /usr/bin/ps [-edaxzflP] [-u ulist] [-g glist] [-p plist] [-t tlist] [-R prmgroup] [-Z psetidlist]
TT=
+ + /usr/bin/sed -e /TTY/d
+ echo
TTNo=
+ + /usr/bin/w
+ /usr/bin/awk { print $5 }
+ /usr/bin/sed -n -e /pts\//p
TIME=-n
+ echo 17766 has been idle for -n
17766 has been idle for -n
+ [[ -n = *day* ]]
+ IDLE=-n
proc.sh[29]: -n: The specified number is not valid for this command.

And this on HP-UX, right? You are ignoring the information I linked in my first post in this thread. Set UNIX95 if you want this to work.

Yeah i got it. Thanks.

I set the UNIX95 paremeter in my script and now ps -o works perfectly but again throwing error at some point. i am trying to read some man pages and fix it in the mean while let me know if you have more idea. here is the below output of the script

+ 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 5835 ]]
+ [[ 5835 != +([0-9]) ]]
+ PID=5835
+ + which w
W=/bin/w
+ + which ps
PS=/bin/ps
+ + which sed
SED=/bin/sed
+ + which awk
AWK=/bin/awk
+ + /bin/ps -o tty4 5835
+ UNIX95=1
/bin/ps: tty4 is not a valid field name
TTY=
+ + /bin/sed -e /TTY/d
+ echo
TTNo=
+ + /bin/w
+ /bin/awk { print $5 }
+ /bin/sed -n -e /pts\//p
TIME=-n
+ echo 5835 has been idle for -n
5835 has been idle for -n
+ [[ -n = *day* ]]
+ IDLE=-n
proc.sh[29]: -n: The specified number is not valid for this command.

Thanks Guru's

Guru's

I think the below line attaching the process to tty.

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

because when executing this line i get the error.

crypto $ UNIX95=1 ps -o tty4 $PID
ps: tty4 is not a valid field name

I think i have to give tty there. please let me know.

crypto $ UNIX95=1 ps -o tty
TT
pts/0
pts/0
crypto $ UNIX95=1 ps -o tty4
ps: tty4 is not a valid field name

Could you please let me know. my system contains the below terminal.

crypto $ w
7:04pm up 100 days, 14 mins, 2 users, load average: 0.01, 0.01, 0.01

User tty login@ idle JCPU PCPU what

root console 8:02pm2400:02 ksh -o vi
x033870 pts/0 5:36pm w

let me know anything i have to change.

Vino is a Linux user and that tty4 thing seems to be a Linux only option. Linux seems to have 4 ways to specify tty in the -o option: tt, tty, tty4, and tty8. Here I just tried all 4 of them:

$ for t in tt tty tty4 tty8 ; do ps -o $t,pid -p 805,992; done
TT         PID
tty1       805
pts/1      992
TT         PID
tty1       805
pts/1      992
TTY    PID
1      805
1      992
TTY        PID
tty1       805
pts/1      992
$

So TT and TTY are identical. TTY8 changes the title to TTY. And while TTY4 also changes the title to TTY, it has the nasty effect of not showing enough info to be useful. Note that we cannot tell tty1 from pts/1 with TTY4.

So yes, you need to use TTY since that is all that HP-UX has. But even if TTY4 was available I don't think you should use it.

Thanks for your comment on this. Now i replaced tty in the script instead of tty4 but i get a error saying invalid option specifying the process id there.

Below is the output.

crypto $ sh -x proc_new.sh 17096
+ 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 17096 ]]
+ [[ 17096 != +([0-9]) ]]
+ PID=17096
+ + which w
W=/bin/w
+ + which ps
PS=/bin/ps
+ + which sed
SED=/bin/sed
+ + which awk
AWK=/bin/awk
+ + /bin/ps -o tty 17096
+ UNIX95=1
/bin/ps: Unknown option (17096).
TTY=
+ + /bin/sed -e /TTY/d
+ echo
TTNo=
+ + /bin/w
+ /bin/awk { print $5 }
+ /bin/sed -n -e /pts\//p
TIME=
+ echo 17096 has been idle for
17096 has been idle for
+ [[ = *day* ]]
+ IDLE=
+ [[ -gt 30 ]]

Please let me know any idea.

Look at the code I posted above. You need a -p before the pid.

Yep it works great thanks. Now i get a different error with sed command where that "sed: Function /pts\/TT cannot be parsed."

i replaced the double quotes with single quotes in sed command it works but i am not getting any output properly.but itz not calculating any time there.

here is the complete output of the script.

crypto $ sh -x proc_new.sh 278
+ 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 278 ]]
+ [[ 278 != +([0-9]) ]]
+ PID=278
+ + which w
W=/bin/w
+ + which ps
PS=/bin/ps
+ + which sed
SED=/bin/sed
+ + which awk
AWK=/bin/awk
+ + /bin/ps -o tty -p 278
+ UNIX95=1
TTY=TT
pts/0
+ + /bin/sed -e /TTY/d
+ echo TT
pts/0
TTNo=TT
pts/0
+ + /bin/w
+ /bin/awk { print $5 }
+ /bin/sed -n -e /pts\/$TTNo/p
TIME=
+ echo 278 has been idle for
278 has been idle for
+ [[ = *day* ]]
+ IDLE=
+ [[ -gt 30 ]]

without -x the output comes like below.

crypto $ sh proc_new.sh 278
278 has been idle for

no time nothing is coming.

I tried with the script line by line but i think there somethng needs to be changed when attaching process to TTY.

Could you please help me. I still get the same error as above.

Request you to help me guru's.

Thanks.

Guru's

Any update on this. I use a HP ux and i need to find the process idle time.

I couldn't get it using this script. Please help me gurus. This will be very helpful for my administration task. I daily used to kill some 300 idle processes.

Please help.

Please throw some lights on this.