Re: /proc/cpuinfo consistency

Keith Owens (kaos@ocs.com.au)
Mon, 21 Sep 1998 09:45:19 +1000


On Sun, 20 Sep 1998 13:11:01 -0400 (EDT),
Alex Buell <alex.buell@tahallah.demon.co.uk> wrote:
>I *wouldn't* mind the difference so much if they'd made it use all lower
>case letters *and* a space before the ':' and a space after that. Then I
>would have no problems parsing the /proc/cpuinfo file at all.
>
>i.e, on Amiga-Linux they have this horrible thing:
>CPU: 68040
>BogoMips: 16.58
>
>whilst on Intel it's as:
>cpu family : 6
>model : 5
>model_name : Pentium II
>bogomips : 400.59

regex is your friend. In perl

while (<>) {
chop();
$cpu = $2 if (/^cpu( family)?\s*:\s*(\S*)/i);
$model = $1 if (/^model\s*:\s*(\S*)/i);
$model_name = $1 if (/^model name\s*:\s*(\S*)/i);
$bogomips += $1 if (/^bogomips\s*:\s*(\S*)/i);
}

$cpu = $model_name if($model_name);
print "cpu=$cpu\n";
print "bogomips=$bogomips\n";

Converting to regexec for C is left as an exercise for the reader :).

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/