1819804 Members
2921 Online
109607 Solutions
New Discussion юеВ

ps command and %CPU

 
SOLVED
Go to solution
OLIVA_1
Regular Advisor

ps command and %CPU

Hello,

I would like monitoring some proceses and I need to know the %CPU used.
With Solaris I can used the ps -aux command but it doesn't display %CPU field on HP-UX...

Someone can help me ?

Thanks,
9 REPLIES 9
OLIVA_1
Regular Advisor

Re: ps command and %CPU

# /usr/ucb/ps -aux | more
USER PID %CPU %MEM SZ RSS TT S START TIME COMMAND
root 1617 2.1 22.8926424916624 ? S Jan 26 1949:14 /opt/eh55/bin/sys/
root 5252 0.1 0.1 1816 1344 pts/1 O 13:30:28 0:00 /usr/ucb/ps -aux
root 3 0.1 0.0 0 0 ? S Jan 26 15:20 fsflush
eh 1618 0.1 2.310068892960 ? S Jan 26 12:15 /opt/eh55/bin/sys/
root 463 0.0 0.312944 8992 ? S Jan 26 5:50 /opt/VRTSvmsa/jre/
root 2841 0.0 0.1 5840 2336 ? S 13:08:40 0:00 /usr/local/sbin/ss
root 5251 0.0 0.1 1248 992 pts/1 S 13:30:28 0:00 more
root 0 0.0 0.0 0 0 ? T Jan 26 0:00 sched
root 1 0.0 0.0 888 368 ? S Jan 26 2:26 /etc/init -


I would like the field %CPU

Thanks
Stephen Keane
Honored Contributor

Re: ps command and %CPU

Use top instead.
john korterman
Honored Contributor

Re: ps command and %CPU

Hi,
the top command in hpux can tell you the % usage of a process.
regards,
John K.
it would be nice if you always got a second chance
OLIVA_1
Regular Advisor

Re: ps command and %CPU

I know top command displays %CPU... but I need a command which could be used in a shell script. Indeed I need to follow a process for a week.
john korterman
Honored Contributor
Solution

Re: ps command and %CPU

Hi again,
then try customizing, e.g.:
# UNIX95= ps -eo comm -o pcpu

notice the space before the ps comand. Consult the man page for ps.

regards,
John K.
it would be nice if you always got a second chance
OLIVA_1
Regular Advisor

Re: ps command and %CPU

Thanks John !!!

It works properly.
Could you please explain me what does ti mean "UNIX95=" ?

And what I have some results up to 100%... for instanca I have a process which used 201.5 % of CPU ?

Thanks.
Kent Ostby
Honored Contributor

Re: ps command and %CPU

Oliva --

I use the following:

ps -ef | cut -c42-80 | sort -nr | head

This will list the top 10 processes by CPU from the PS command.

I'll use it a few times in a row to see what's eating the CPU right now.
"Well, actually, she is a rocket scientist" -- Steve Martin in "Roxanne"
Keith Bryson
Honored Contributor

Re: ps command and %CPU

Hi Oliva

You will have more than 100% CPU depending on how many CPUs you have. If you have 8 CPUs, you can run up to 800%.

The UNIX95 variable is set to enable XPG4 compatibility with certain commands. See 'man ps' for more information

Keith
Arse-cover at all costs
john korterman
Honored Contributor

Re: ps command and %CPU

Hi,
In this case, when UNIX95 is not set, the ps command behaves in hpux as laid down for hpux.
Setting UNIX95 means using standard features of various unix flavours enabled by a group of persons referred to as the Xopen Posix Group. This means changing the whole behaviour of the ps command, gaining access to non-hp standard features.
However, setting UNIX95 may influence other commands then just ps, so I would recommend that you execute it only as specified with the space after the equal sign - if not, it is difficult to describe the influence on other commands.
I am sorry to say that I cannot explain why some commands use 200% cpu: is it a multiprocessor system where commands may take resources from more than a single cpu?
Perhaps others har better explanations.

regards,
John K.
it would be nice if you always got a second chance