From: janne@seita.oulu.fi (Janne Himanka) Subject: Source for "free" in perl. Apply within. Date: 14 Jan 1993 00:43:37 GMT
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";