From: Andrew Derry (derry@beaufort.sfu.ca)
Date: 01/13/93


From: derry@beaufort.sfu.ca (Andrew Derry)
Subject: Re: Source for "free" in perl. Apply within.
Date: Thu, 14 Jan 1993 03:28:37 GMT

janne@seita.oulu.fi (Janne Himanka) writes:

>The procps free was a bit too simplistic for me so I threw together
>this little perl free. It uses /proc file system and shows figures in
>kilobytes. It seems that /proc/meminfo is not wholesome: the "memory
>used" figure appears to be far too big.

>-Janne

>%%%%%%%%%%%%%%%%% snip snip %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
>#!/usr/local/bin/perl

>open (MEMINFO, "/proc/meminfo");

><MEMINFO>; # Throw away the original title

>@mem = split(/\s+/, <MEMINFO>);
>print "\tTOTAL\tUSED\tFREE\tSHARED\tBUFFERS\n";
>print $mem[0];
>foreach $i (1..5) { $mem[$i] = int($mem[$i]/1000); }
>print "\t$mem[1]\t$mem[2]\t$mem[3]\t$mem[4]\t$mem[5]\n";

>@swap = split(/\s+/, <MEMINFO>);
>close MEMINFO;
>exit if ($swap[1] == 0);
>print $swap[0];
>foreach $i (1..3) { $swap[$i] = int($swap[$i]/1000); }
>print "\t$swap[1]\t$swap[2]\t$swap[3]\n";

I tried the above program, just out of curiosity.. all I got was:

        TOTAL USED FREE SHARED BUFFERS
        0 0 0 0 0

I assume that is not the intended output...