[PLUG] perl reading /proc/loadavg

lemming at attbi.com lemming at attbi.com
Thu Mar 21 23:12:21 UTC 2002


Because you're still reading the same file as it was 
when you first opened it.
Instead of seek, etc... just reopen the file.

-Mark
> 
> 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
> 
> 
> _______________________________________________
> PLUG mailing list
> PLUG at lists.pdxlinux.org
> http://lists.pdxlinux.org/mailman/listinfo/plug




More information about the PLUG mailing list