From owner-freebsd-ports@FreeBSD.ORG Wed Jan 25 14:08:06 2006 Return-Path: X-Original-To: ports@freebsd.org Delivered-To: freebsd-ports@FreeBSD.ORG Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 02CA716A420 for ; Wed, 25 Jan 2006 14:08:06 +0000 (GMT) (envelope-from fernan@iib.unsam.edu.ar) Received: from smtp.unsam.edu.ar (smtp.unsam.edu.ar [170.210.48.3]) by mx1.FreeBSD.org (Postfix) with ESMTP id CDABE43D45 for ; Wed, 25 Jan 2006 14:08:01 +0000 (GMT) (envelope-from fernan@iib.unsam.edu.ar) Received: from pi.iib.unsam.edu.ar (pi.iib.unsam.edu.ar [192.168.10.11]) by smtp.unsam.edu.ar (8.12.6/8.12.6) with ESMTP id k0PE5KUr019918; Wed, 25 Jan 2006 11:05:20 -0300 (ART) (envelope-from fernan@iib.unsam.edu.ar) Received: from pi.iib.unsam.edu.ar (localhost [127.0.0.1]) by pi.iib.unsam.edu.ar (8.13.1/8.13.1) with ESMTP id k0PE7ZvF080053; Wed, 25 Jan 2006 11:07:35 -0300 (ART) (envelope-from fernan@iib.unsam.edu.ar) Received: (from fernan@localhost) by pi.iib.unsam.edu.ar (8.13.1/8.13.1/Submit) id k0PE7WND080052; Wed, 25 Jan 2006 11:07:32 -0300 (ART) (envelope-from fernan@iib.unsam.edu.ar) X-Authentication-Warning: pi.iib.unsam.edu.ar: fernan set sender to fernan@iib.unsam.edu.ar using -f Date: Wed, 25 Jan 2006 11:07:32 -0300 From: Fernan Aguero To: Gary Jennejohn Message-ID: <20060125140731.GB79842@iib.unsam.edu.ar> Mail-Followup-To: Gary Jennejohn , FreeBSD Ports References: <20060124172317.GF72149@iib.unsam.edu.ar> <200601242058.k0OKwH2i016170@peedub.jennejohn.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200601242058.k0OKwH2i016170@peedub.jennejohn.org> User-Agent: Mutt/1.5.9i Cc: FreeBSD Ports Subject: Re: porting an app that checks /proc/meminfo X-BeenThere: freebsd-ports@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Porting software to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 25 Jan 2006 14:08:06 -0000 +----[ Gary Jennejohn (24.Jan.2006 18:02): | | Fernan Aguero writes: | > I've got a port ready for muscle | > | > WWW: http://www.drive5.com/muscle/ | > Port: http://genoma.unsam.edu.ar/~fernan/freebsd/muscle.shar | > | > The program builds fine, but because it uses /proc/meminfo | > to check for available memory, when you run it, it will | > complain about the lack of /proc/meminfo and won't let you | > do anything. | > | > The author, has suggested a hack (see globalslinux.cpp | > and patch-globalslinux.cpp in the port) that disables the | > function that returns the amount of memory used by muscle | > and the amount of RAM available in the computer. With this | > patch muscle runs fine but i) the progress messages will | > give incorrect values for current memory use & fraction of | > available RAM and ii) muscle may fail to fail gracefully | > when it runs out of memory, it may just crash. | > | > I'm not a C programmer, and the author is not familiar with | > BSD internals ... I'm trying to help by pointing him in the | > right direction. So my question can be summarized as: | > | > How does one gets the values of i) memory used by the | > program/process and ii) amount of RAM available in the | > computer without using /proc/meminfo in FreeBSD? | > | > Suggestion of places to look (man pages) and/or examples in | > C are welcomed. The functions that need to be modified are | > GetMemUseMB and GetRAMSizeMB in globalslinux.cpp. | > | > OTOH, I know we have linprocfs ... but AFAIK it will mount under | > /compat/linux/proc ... and given that the muscle executable | > is FreeBSD native it will not check there ... am I right? | > | | A good place to look at is /usr/src/usr.bin/top/machine.c. This is | FreeBSD specific and grabs the memory and process information from | the kernel. Gary, thanks for your suggestion. I'll look into it. However, let me ask you a naive question ... isn't there any OS agnostic way of getting these values? As I wrote in my reply to Brooks, perhaps some call that, although implemented differently in each OS, will have the same API for a programmer. So s/he can use it across different Unix OSes? Otherwise the code will end up looking something like: if FreeBSD use sysctlbyname elsif NetBSD something other elsif Linux yet another way elsif Win32 ... else whoops, you are running an OS that we haven't seen before and we have to learn yet another way to check available RAM endif Again, I'm not versed in C, I just have the impression that such a generic call should exist ... or perhaps I've been dreaming? :) | top uses sysctlbyname(3) to get the memory info and kvm_getprocs(3) to | get the process-specific stuff. | | There seem to be 3 sysctl's of interest: hw.physmem, hw.usermem and | hw.realmem. Here's output on my machine: | | hw.physmem: 2138202112 | hw.usermem: 1953370112 | hw.realmem: 2147155968 | | realmem > physmem > usermem. | +----] OK, if I don't find my generic call, I'll suggest to implement these FreeBSD specific calls. Thanks again, Fernan