From owner-freebsd-questions Thu Jul 2 11:52:17 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id LAA17314 for freebsd-questions-outgoing; Thu, 2 Jul 1998 11:52:17 -0700 (PDT) (envelope-from owner-freebsd-questions@FreeBSD.ORG) Received: from antipodes.cdrom.com (castles224.castles.com [208.214.165.224]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id LAA17154; Thu, 2 Jul 1998 11:51:03 -0700 (PDT) (envelope-from mike@antipodes.cdrom.com) Received: from antipodes.cdrom.com (localhost [127.0.0.1]) by antipodes.cdrom.com (8.8.8/8.8.5) with ESMTP id LAA01417; Thu, 2 Jul 1998 11:50:04 -0700 (PDT) Message-Id: <199807021850.LAA01417@antipodes.cdrom.com> X-Mailer: exmh version 2.0zeta 7/24/97 To: Donn Miller cc: Mike Smith , questions@FreeBSD.ORG, hackers@FreeBSD.ORG Subject: Re: FreeBSD equiv. of /proc/loadavg In-reply-to: Your message of "Thu, 02 Jul 1998 14:37:21 -0000." <359B9B21.6DE01652@bellatlantic.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Thu, 02 Jul 1998 11:50:04 -0700 From: Mike Smith Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG > 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