Operating System - HP-UX
1753844 Members
7495 Online
108806 Solutions
New Discussion юеВ

Script required for tracking processes which utilizing 98 % and above cpu resources.

 
Siddhesh
Advisor

Script required for tracking processes which utilizing 98 % and above cpu resources.

Hi Gurus,

I am in need to trace the processes which are utilizng above 98% of cpu resourses at any point of time . Can anyone help me out in writing a script for the same.

Thanks,
spv
7 REPLIES 7
Stefan Farrelly
Honored Contributor

Re: Script required for tracking processes which utilizing 98 % and above cpu resources.

This command will list all processes by cpu usage;

UNIX95= ps -eo "pid ruser pcpu vsz=Kbytes" -o args |sort -r -k 3

All you need to do is use awk to put the 3rd column into a variable and if its >98% then do whatever you want as that process is using 98% of the cpu.

Im from Palmerston North, New Zealand, but somehow ended up in London...
Siddhesh
Advisor

Re: Script required for tracking processes which utilizing 98 % and above cpu resources.

Hi ,

Is ps -eo option working in hpux-11.i?

thks,
spv
Michael Schulte zur Sur
Honored Contributor

Re: Script required for tracking processes which utilizing 98 % and above cpu resources.

Hi Siddhesh,

it is , if you set UNIX95 for the sake backward compatibility.

Hi Stefan,

have you been missing the 1 in UNIX95 or doesnt it matter, whats in there?

greetings,

Michael
Graham Cameron_1
Honored Contributor

Re: Script required for tracking processes which utilizing 98 % and above cpu resources.

ps -eo works for me on 11i, but the sort -k3 doesn't.

However,
ps -eo "pid ruser pcpu vsz=Kbytes" -o args|awk '$3>=98'
seems to do what you need.

Stick it in a loop and do what you want with the output...

-- Graham
Computers make it easier to do a lot of things, but most of the things they make it easier to do don't need to be done.
Michael Schulte zur Sur
Honored Contributor

Re: Script required for tracking processes which utilizing 98 % and above cpu resources.

Hi Graham,

it works only if you set UNIX95 for example to 1.

greetings,

Michael
Bill Hassell
Honored Contributor

Re: Script required for tracking processes which utilizing 98 % and above cpu resources.

It's important to understand what UNIX95= is actually doing. In the man page for ps, you will see references to 'special' options like -o -C -H which are illegal in a normal ps run. These are XPG4 behavior options and can only be activated when the variable UNIX95 is defined. HOWEVER, UNIX95 is a variable that affects other programs and libraries so you DON'T want to set UNIX95 permanently as in:

export UNIX95=

(UNIX95= defines the variable and sets the value to null) So the construct: UNIX95= ps ... is used to temporarily define UNIX95 (the value is unimportant) for the duration of ps and then remove it. So even though it looks strange, the POSIX shell (and ksh and bash, etc) allow definition of a variable followed by a command, all in the same command line.


Bill Hassell, sysadmin
Michael Schulte zur Sur
Honored Contributor

Re: Script required for tracking processes which utilizing 98 % and above cpu resources.

Hi Siddhesh,

is your problem solved? If so, could you please award some points to those, who could help you?

greetings,

Michael