File: physical_cpus.pl

package info (click to toggle)
libparse-dmidecode-perl 0.03-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 336 kB
  • sloc: perl: 1,150; makefile: 4
file content (33 lines) | stat: -rw-r--r-- 660 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/perl -w

use 5.6.1;
use strict;
use warnings;
use Parse::DMIDecode qw();

my $dmi = Parse::DMIDecode->new( nowarnings => 1 );
$dmi->probe;

my $physical_cpus = 0;
for my $handle ($dmi->get_handles(group => "processor")) {
	my $type = ($handle->keyword("processor-type") or "");
	next unless $type =~ /Central Processor/i;

	# Check the status of the cpu
	my $status = ($handle->keyword("processor-status") or "");
	if ($status !~ /Unpopulated/i) {
		$physical_cpus++;
	}
}

printf("There %s %d physical %s in this machine.\n",
		($physical_cpus == 1 ? "is" : "are"),
		$physical_cpus,
		($physical_cpus == 1 ? "CPU" : "CPUs"),
	);

exit;

__END__