8

I can use 'prtdiag' to get number of CPU by prtdiag command.

$ prtdiag
System Configuration:  Sun Microsystems  sun4u Sun Fire 6800
System clock frequency: 150 MHz
Memory size: 4096 Megabytes

========================= CPUs 
===============================================

             CPU      Run    E$   CPU      CPU
FRU Name    ID       MHz    MB   Impl.    Mask
----------  -------  ----  ----  -------  ----
/N0/SB1/P2    6      1200   8.0  US-III+  11.0
/N0/SB1/P3    7      1200   8.0  US-III+  11.0
/N0/SB3/P2   14      1200   8.0  US-III+  11.0
/N0/SB3/P3   15      1200   8.0  US-III+  11.0

But, I don't know is there any command could get the number (4 in this example)to let my script use it?

4 Answers4

11

With modern CPUs and their multi-core, multi-thread technologies, you need to define more precisely what you want to count but in your case, psrinfo better suits the job:

psrinfo -p

Note that prtdiag wasn't designed to be parseable and might return a very different output depending on the hardware.

jlliagre
  • 14,369
3

Here is a simple set of pipes using psrinfo:

psrinfo -v | grep ^Status | tail -1 | awk '{x = $5 + 1; print "CPUs: " x;}'

Example output:

CPUs: 6

serv-inc
  • 538
  • 1
  • 4
  • 18
Brad
  • 31
0

How about

prtdiag | grep -c "^/"

To use the resulting value in a script, use $(prtdiag | grep -c "^/").

0

Here is a good script to find all the CPU, cores, virtual CPU (threads)

https://blogs.oracle.com/mandalika/entry/solaris_show_me_the_cpu