#!/usr/bin/perl -w use strict; use Getopt::Long; # If it comes to parallelizing, How many processes do we allow to start # default is amount of CPUs on that system. May be overridden by commandline my $cpu = &num_cpus; my $goback = GetOptions('cpu=i', \$cpu, 'c=i', \$cpu, 'help', \&cmdline_usage, 'h', \&cmdline_usage); print "Number of CPUs here: $cpu\n"; print "Goback was: $goback\n"; # {{{ get the number of CPUs on that system # returns: number of CPUs or 1 if no /proc/cpuinfo was found sub num_cpus { my $num_cpus = 0; my $infofile = '/proc/cpuinfo'; if($^O eq 'linux') { # Yes this is Linux we're running on if(-e $infofile) { # and cpuinfo exists open FILE, $infofile; while() { $num_cpus++ if(/processor/); } close FILE; } } # elsif ... your favourite OS detection routine here # If this is not a known OS we're running on ($num_cpus is then 0) # so better be careful and assume 1 CPU return $num_cpus || 1; } # }}}