Operating System - HP-UX
1754787 Members
4041 Online
108825 Solutions
New Discussion юеВ

Detect number of CPUs as non-root user

 
SOLVED
Go to solution
Peter Fuchs
New Member

Detect number of CPUs as non-root user

Hi,

when writing a perl script that should run on several Unix platforms, I came to a problem when trying to detect the number of CPUs installed in our HP rx2600 server (HP-UX 11.23).
When logged in as root this could be easily done using "/opt/ignite/bin/print_manifest" however, this utility can only be run as root.

Is there any way of detecting the number of CPUs directly (without workarounds like cronjobs run by root etc.) as non-root user?

Thanks in advance!

Peter
7 REPLIES 7
twang
Honored Contributor
Solution

Re: Detect number of CPUs as non-root user

# sar -M 2 2

the above command should report the per-processor data on a multi-processor system. Output format and the data reported is the average value of all the active processors.
twang
Honored Contributor

Re: Detect number of CPUs as non-root user

For example, on a dual cpu system(L2000), it reports:
# sar -M 2 2

HP-UX macerp B.11.11 U 9000/800 04/26/04

14:14:44 cpu %usr %sys %wio %idle
14:14:46 0 30 12 12 46
1 29 7 1 63
system 29 9 7 54
14:14:48 0 62 10 1 26
1 62 7 6 25
system 62 9 4 25

Average 0 46 11 7 36
Average 1 46 7 4 44
Average system 46 9 5 40
Elmar P. Kolkman
Honored Contributor

Re: Detect number of CPUs as non-root user

top is a solution. Or you could try:
UNIX95= ps -o cpu | sort -un

That will report all CPU's running processes. But it is not reliable. You might need to run it at least a couple of times to get all available CPU numbers. I think it is better to do it this way:
top -d 1 | awk '/^CPU/,/^avg/ { print $1 }'
It will report the first columns of your CPU part of top, which will show what you want, I guess.
Every problem has at least one solution. Only some solutions are harder to find.
Sunil Sharma_1
Honored Contributor

Re: Detect number of CPUs as non-root user

Hi,

top and sar -M can be used.

Sunil
*** Dream as if you'll live forever. Live as if you'll die today ***
V.Tamilvanan
Honored Contributor

Re: Detect number of CPUs as non-root user

Hi,

You can find with top command.

$top
Elmar P. Kolkman
Honored Contributor

Re: Detect number of CPUs as non-root user

A problem with top can be the escape codes send to format on a terminal. So you might have to change my top solution to:
TERM=ansi top -d 1 | awk '/^CPU.*LOAD/,/^---.*----/ {print $1}'
Every problem has at least one solution. Only some solutions are harder to find.
Peter Fuchs
New Member

Re: Detect number of CPUs as non-root user

Hi again,

Thanks to all for your quick help!

I think I will go for the "sar"-solution as it seems to be the easiest for me.


Rgs,

Peter