The following possibly-useful fragments ask most Unix systems (I've tried it on BSD and Mac) how many processors there are.
(t)csh:
set nproc = `sysctl -n hw.ncpu`
bash/ksh:
nproc=`sysctl -n hw.ncpu`
Python:
···
from subprocess import Popen
def getnproc():
GETN = 'sysctl -n hw.ncpu'
nproc = 1
sysc = Popen(GETN.split(), stdout=PIPE)
(out,junk) = sysc.communicate()
if sysc.returncode == 0:
nproc = int(out)
return nproc
--
Randolph
What a nice little Friday afternoon gift. Thanks Randolph!
···
On Fri, Oct 8, 2010 at 12:26 PM, Randolph M. Fritz <RFritz@lbl.gov> wrote:
The following possibly-useful fragments ask most Unix systems (I've tried
it on BSD and Mac) how many processors there are.
(t)csh:
set nproc = `sysctl -n hw.ncpu`
bash/ksh:
nproc=`sysctl -n hw.ncpu`
Python:
from subprocess import Popen
def getnproc():
GETN = 'sysctl -n hw.ncpu'
nproc = 1
sysc = Popen(GETN.split(), stdout=PIPE)
(out,junk) = sysc.communicate()
if sysc.returncode == 0:
nproc = int(out)
return nproc
--
Randolph
_______________________________________________
Radiance-general mailing list
Radiance-general@radiance-online.org
http://www.radiance-online.org/mailman/listinfo/radiance-general
--
Rob Guglielmetti
www.rumblestrip.org
Unfortunately, this doesn't work on Linux, bah!
On Linux, the following shell command will do it:
grep 'processor' /proc/cpuinfo |wc -l
I wonder what works on Solaris...
···
--
Randolph
On 08/10/10, 19:26:11, Randolph "M." Fritz <RFritz@lbl.gov> wrote regarding
[Radiance-general] ...how many processors?:
The following possibly-useful fragments ask most Unix systems (I've
tried it on BSD and Mac) how many processors there are.
(t)csh:
set nproc = `sysctl -n hw.ncpu`
bash/ksh:
nproc=`sysctl -n hw.ncpu`
sysctl is not available on Solaris. For Solaris I use:
$ psrinfo | wc -l
4
It's more rigourous to look for on-line processors (but I don't ever off
line mine):
# psrinfo | grep -c on-line
4
# psradm -f 2
# psrinfo | grep -c on-line
3
That gives the number of virtual processors which usually is good enough,
to get more detail use (Solaris 9+):
$ psrinfo -vp
The physical processor has 2 virtual processors (0 1)
x86 (chipid 0x0 AuthenticAMD family 15 model 65 step 3 clock 2613 MHz)
Dual-Core AMD Opteron(tm) Processor 2218 HE
The physical processor has 2 virtual processors (2 3)
x86 (chipid 0x1 AuthenticAMD family 15 model 65 step 3 clock 2613 MHz)
Dual-Core AMD Opteron(tm) Processor 2218 HE
or for even more system detail:
$ prtdiag
System Configuration: Sun Microsystems Sun Fire X2200 M2
BIOS Configuration: Sun Microsystems S39_3B25 11/15/2007
BMC Configuration: IPMI 1.5 (KCS: Keyboard Controller Style)
==== Processor Sockets ====================================
Version Location Tag
-------------------------------- --------------------------
Dual-Core AMD Opteron(tm) Processor 2218 HE U
Dual-Core AMD Opteron(tm) Processor 2218 HE U
...etc...
James.