Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 02 Jul 1998 11:50:04 -0700
From:      Mike Smith <mike@smith.net.au>
To:        Donn Miller <dmm125@bellatlantic.net>
Cc:        Mike Smith <mike@smith.net.au>, questions@FreeBSD.ORG, hackers@FreeBSD.ORG
Subject:   Re: FreeBSD equiv. of /proc/loadavg 
Message-ID:  <199807021850.LAA01417@antipodes.cdrom.com>
In-Reply-To: Your message of "Thu, 02 Jul 1998 14:37:21 -0000." <359B9B21.6DE01652@bellatlantic.net> 

next in thread | previous in thread | raw e-mail | index | archive | help
> Mike Smith wrote:
> > 
> > >
> > > Am looking for the FreeBSD equivalent of the Linux file /proc/loadavg.  I
> > > want to use this instead of using getloadavg().
> > 
> > The obvious question here is "why"?
> 
> I just figured that some Linux programs were trying to obtain load
> average info that way, and to ease porting, well, I wanted to open the
> equivalent FreeBSD file.  I realize now though that if you want to port
> some apps with low-level details, you gotta do a little reworking.

Yup.  Particularly when you're dealing with code written for Linux 
(where NIH is considered a virtue...).

Consider the Linux approach:

	FILE	*fp;
	double	la[3];

	if ((fp = fopen("/proc/loadavg")) == NULL)
		error();
	if (fscanf(fp, "%f %f %f", la, la+1, la+2) != 3)
		error();
	fclose(fp);
	
vs.

	double	la[3];

	if (sysctlbyname("vm.loadavg", NULL, 0, la, sizeof(la)))
		error();

Now rank them on simplicity, efficiency, and adherence to KISS.  8)

> I was trying to port wmmon from WindowMaker.  It's just for Linux now. 
> In addition, the app tries to obtain loadaverage, uptime, and memory
> info about the machine like this: (from wmmon.c)
> 
> FILE    *fp_meminfo;
> FILE    *fp_stat;
> FILE    *fp_loadavg;
> 
> 
> /*.....*/
>  fp = fopen("/proc/uptime", "r");  
>         fp_meminfo = fopen("/proc/meminfo", "r");
>         fp_loadavg = fopen("/proc/loadavg", "r");
>         fp_stat = fopen("/proc/stat", "r");

Any application written to use the Linux idea of "memory use" is not 
going to work well when presented with the way that FreeBSD uses 
memory.

You're probably up for seriously reworking this - have a look at the 
way that systat gets the numbers you're interested in.

-- 
\\  Sometimes you're ahead,       \\  Mike Smith
\\  sometimes you're behind.      \\  mike@smith.net.au
\\  The race is long, and in the  \\  msmith@freebsd.org
\\  end it's only with yourself.  \\  msmith@cdrom.com



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199807021850.LAA01417>