How to find number of CPUs

Y

Yash

Can you please tell me how to find the number of CPUs present on a PC
using Perl 5.6 on Windows 2000?

Thanks
 
M

Matt Garrish

Yash said:
Can you please tell me how to find the number of CPUs present on a PC
using Perl 5.6 on Windows 2000?

It's an environment variable. Check your environment:

perl -e "print $ENV{NUMBER_OF_PROCESSORS}"

Before posting you should find out how you would normally locate this
information, and only ask here if you can't find any conceivable way to do
so using Perl.

Matt
 
P

Petri

Can you please tell me how to find the number of CPUs present on a
PC using Perl 5.6 on Windows 2000?

WMI is your friend:
http://msdn.microsoft.com/library/en-us/dnanchor/html/anch_wmi.asp?frame=true

More on Windows scripting:
http://msdn.microsoft.com/nhp/Default.asp?contentid=28001169&frame=true

Excerpt from stuff I had lying around:
---8<---
#!/usr/bin/perl -w
use strict;
use warnings;
use Win32::OLE qw(in with);

my $wmi;
eval { # Wrap in eval to catch errors in object creation.
$wmi = Win32::OLE->GetObject("winmgmts:");
};

unless ($@) {
print "Processor info\n";
print "-" x 30,"\n";
my $cpu_set = $wmi->InstancesOf("Win32_Processor");
foreach my $cpu (in($cpu_set)) {
print "Name: ".$cpu->{'Name'}."\n" if $cpu->{'Name'};
print "Caption: ".$cpu->{'Caption'}."\n" if $cpu->{'Caption'};
print "Architecture: ".$cpu->{'Architecture'}."\n" if
$cpu->{'Architecture'};
print "Description: ".$cpu->{'Description'}."\n" if
$cpu->{'Description'};
print "Family: ".$cpu->{'Family'}."\n" if $cpu->{'Family'};
print "Other Family Desc: ".$cpu->{'OtherFamilyDescription'}."\n" if
$cpu->{'OtherFamilyDescription'};
print "Manufacturer: ".$cpu->{'Manufacturer'}."\n" if
$cpu->{'Manufacturer'};
print "ProcessorID: ".$cpu->{'ProcessorID'}."\n" if
$cpu->{'ProcessorID'};
print "ProcessorType: ".$cpu->{'ProcessorType'}."\n" if
$cpu->{'ProcessorType'};
print "Revision: ".$cpu->{'Revision'}."\n" if $cpu->{'Revision'};
print "System Name: ".$cpu->{'SystemName'}."\n" if $cpu->{'SystemName'};
print "Version: ".$cpu->{'Version'}."\n" if $cpu->{'Version'};
print "Status Info: ".$cpu->{'StatusInfo'}."\n" if $cpu->{'StatusInfo'};
print "Current Voltage: ".$cpu->{'CurrentVoltage'}."\n" if
$cpu->{'CurrentVoltage'};
print "DeviceID: ".$cpu->{'DeviceID'}."\n" if $cpu->{'DeviceID'};
print "Status: ".$cpu->{'Status'}."\n" if $cpu->{'Status'};
print "Data Width: ".$cpu->{'DataWidth'}." bit\n" if
$cpu->{'DataWidth'};
print "Clock Speed: ".$cpu->{'CurrentClockSpeed'}." MHz\n" if
$cpu->{'CurrentClockSpeed'};
print "L2 Cache Size: ".$cpu->{'L2CacheSize'}." KByte\n" if
$cpu->{'L2CacheSize'};
print "Level: ".$cpu->{'Level'}."\n" if $cpu->{'Level'};
print "External Clock: ".$cpu->{'ExtClock'}." MHz\n" if $cpu->{'ExtClock'};
print "\n";
}
} else {
die "Win32::OLE->GetObject failed: ", Win32::OLE->LastError, "\n";
}
---8<---

Hope this helps!

Petri
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top