Operating System - HP-UX
1846741 Members
5143 Online
110256 Solutions
New Discussion

Re: track CPU usage for specific process?

 
SOLVED
Go to solution
Dave Chamberlin
Trusted Contributor

track CPU usage for specific process?

Greetings,
I commonly use top to view high resource consumers on my rp8400 (HPUX 11.11). I am interested though in watching some specific jobs (by name) and periodically saving their weighted CPU usage over time. Is there a ps command (or another method) I could use to show the weighted CPU usage for those processes? Thanks
13 REPLIES 13
Pete Randall
Outstanding Contributor
Solution

Re: track CPU usage for specific process?

You need to look at the XPG4 options available for "ps", particularly "-o pcpu".

Something like this:

# UNIX95= ps -ef -o pid,ppid,pcpu,args | sort -nbk 3 | tail -10

would give you the top 10, you would probably want to pipe to grep to select particular processes.


Pete

P.S. Note the space after "UNIX95= "

Pete
Oviwan
Honored Contributor

Re: track CPU usage for specific process?

Hey

here is an example script with 9869 as pid

UNIX95=1 /usr/bin/ps -e -o pcpu,pid,args | grep 9869 | grep -v grep | sed -e 's/\.[0-9][0-9]/&\%/g' |awk '{ print $1 } '

hope this helps

Regards
Jaime Bolanos Rojas.
Honored Contributor

Re: track CPU usage for specific process?

Dave,

Glance is always a good option, remember if you do not have it you could always get a trial version,

Regards,

Jaime.
Work hard when the need comes out.
Dave Chamberlin
Trusted Contributor

Re: track CPU usage for specific process?

Thanks for the suggestions. I do have the -o options (XPG4) on my system (...illegal option -o...). I have glance and can drill down to the procs I am monitoring - but want to get a snapshot of their CPU with an automated script every 10 minutes. Thanks
Dave Chamberlin
Trusted Contributor

Re: track CPU usage for specific process?

oops - correction - I DO NOT have the -o options for ps. thanks
Pete Randall
Outstanding Contributor

Re: track CPU usage for specific process?

Dave,

On 11.11 you absolutely do have the XPG4 options. You need to cut and paste this line exactly as it stands:

UNIX95= ps -ef -o pid,ppid,pcpu,args


Pete

Pete
A. Clay Stephenson
Acclaimed Contributor

Re: track CPU usage for specific process?

Yes, you do have those options for ps. The -o options work when the XPG4 behavior od ps is triggered. That is accomplished by setting and exporting the UNIX95 environment variable. (It only matters if UNIX95 is defined or not; the value UNIX95 is set to is ignored)

so:
export UNIX95=1
ps -o pid,...
-- will work or you can define UNIX95 for a single command:
UNIX95=1 ps -o pid,...
works as well.
If it ain't broke, I can fix that.
Dave Chamberlin
Trusted Contributor

Re: track CPU usage for specific process?

well alrighty then - I guess I do. I am not familiar with that syntax UNIX95= --can you elaborate on that? Thanks - that works fine.
Dave Chamberlin
Trusted Contributor

Re: track CPU usage for specific process?

well alrighty then - I guess I do! :) I am not familiar with that syntax UNIX95= --can you elaborate on that? Thanks - that command works great.
Pete Randall
Outstanding Contributor

Re: track CPU usage for specific process?

Setting the UNIX95 variable invokes the XPG4 standards, which make additional options available to the ps command. See man ps and look for XPG4, UNIX95 and EXTERNAL INFLUENCES.


Pete

Pete
Dave Chamberlin
Trusted Contributor

Re: track CPU usage for specific process?

ok - that makes sense - I didn't realize we were setting an env var - thought it was some new command...Learn something new every day....
A. Clay Stephenson
Acclaimed Contributor

Re: track CPU usage for specific process?

Answer the question yourself:

try this from a shell prompt:
unset X # make sure that X is not already defined
X=1 sh 'echo ${X}' # Note that sh is a separate process
echo ${X} # back in parent




If it ain't broke, I can fix that.
Dennis Handly
Acclaimed Contributor

Re: track CPU usage for specific process?

>Clay: export UNIX95=1

It may be dangerous to set this variable, rather than invoke it just on ps(1).

Patches may fail to unshar due to bugs/fixes in shar(1) and wc(1).

>Clay: X=1 sh 'echo ${X}'

Note this is completely different (in most cases if X isn't exported) than:
$ X=1; sh 'echo ${X}'