Obtain Memory on HP UNIX

PxT pioneered a technique involving invoking pstat from perl. I have been studying the technique in preparation for a script I plan to write. I have tried to write a script to solve your requirement. I may have succeeded. I have only tested it on one system. The total physical memory matches what I from cstm. Free memory matches what I get from vmstat. And the percentages match what I get from glance. So it may be working. But no guarantees. :smiley:

#!/usr/contrib/bin/perl

local($PSTAT, $PSTAT_STATIC, $PSTAT_DYNAMIC) = (239, 2, 3);
local($struct_pst) = ("\0" x 156);
local($struct_psd) = ("\0" x 2904);

syscall($PSTAT, $PSTAT_STATIC, $struct_pst, length($struct_pst), 1, 0);
($pages, $psize) = (unpack("x16LL", $struct_pst));
syscall($PSTAT, $PSTAT_DYNAMIC, $struct_psd, length($struct_psd), 1, 0);
$free = unpack("x64L", $struct_psd);
$mb = ($psize / 1024) * $pages;
$mb = $mb / 1024;
print "Physical Memory: ",$mb,"MB\n";
print "Free Pages: ", $free, "\n";
$pcfree = 100. * $free /$pages;
$pcused = 100. - $pcfree;
printf(" %0.2f%% free          %0.2f%% used \n", $pcfree, $pcused);
exit 0;