How to find number of CPUs

Discussion in 'Perl Misc' started by Yash, Feb 14, 2004.

  1. Yash

    Yash Guest

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

    Thanks
     
    Yash, Feb 14, 2004
    #1
    1. Advertising

  2. Yash

    Matt Garrish Guest

    "Yash" <> wrote in message
    news:...
    > 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
     
    Matt Garrish, Feb 14, 2004
    #2
    1. Advertising

  3. Yash

    Petri Guest

    In article <>, Yash says...
    > 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
     
    Petri, Feb 14, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. RP

    tuning asp.net for HT CPUs

    RP, Aug 23, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    362
    Lucas Tam
    Aug 23, 2004
  2. David
    Replies:
    0
    Views:
    433
    David
    Nov 3, 2004
  3. David
    Replies:
    2
    Views:
    4,930
    Chris Smith
    Nov 10, 2004
  4. Cindi Jenkins
    Replies:
    6
    Views:
    327
  5. Klaas Vantournhout

    preprocessor number of cpus

    Klaas Vantournhout, Apr 25, 2006, in forum: C++
    Replies:
    4
    Views:
    344
    Ian Collins
    Apr 26, 2006
Loading...

Share This Page