[PLUG] perl reading /proc/loadavg

Randy.Dunlap rddunlap at osdl.org
Thu Mar 21 22:29:38 UTC 2002


If I read /proc/loadavg like this (Perl, a la C) (called from a loop):

sub do_loadavg
{
	seek (LOADAVG, 0, 0) or die "error seeking loadavg";
	$loadavg = "nil";
	$loadavg = <LOADAVG>;		# 1 line
	die "error reading loadavg" if !defined($loadavg);
	chomp $loadavg;
	print "load[1, 5, 15], rdyq/ttl_procs, last_pid:  $loadavg\n";
} # end do_loadavg

I don't see the data changing.  :(

Do I need to use sysopen, sysseek, sysread instead?
Or is there some other trick^W technique?

LOADAVG is opened like this:

open (LOADAVG, "</proc/loadavg") or die "cannot open /proc/loadavg\n";

Thanks,
-- 
~Randy





More information about the PLUG mailing list