From owner-freebsd-hackers@FreeBSD.ORG Wed Apr 19 19:47:01 2006 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 6AEC016A40A for ; Wed, 19 Apr 2006 19:47:01 +0000 (UTC) (envelope-from dan@dan.emsphone.com) Received: from dan.emsphone.com (dan.emsphone.com [199.67.51.101]) by mx1.FreeBSD.org (Postfix) with ESMTP id 64B8A43D45 for ; Wed, 19 Apr 2006 19:47:00 +0000 (GMT) (envelope-from dan@dan.emsphone.com) Received: (from dan@localhost) by dan.emsphone.com (8.13.1/8.13.4) id k3JJkrit009319; Wed, 19 Apr 2006 14:46:53 -0500 (CDT) (envelope-from dan) Date: Wed, 19 Apr 2006 14:46:53 -0500 From: Dan Nelson To: Mathieu Prevot Message-ID: <20060419194653.GB18095@dan.emsphone.com> References: <20060419160436.GA6835@scienceclue.ath.cx> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20060419160436.GA6835@scienceclue.ath.cx> X-OS: FreeBSD 5.5-PRERELEASE X-message-flag: Outlook Error User-Agent: Mutt/1.5.11 Cc: freebsd-hackers@freebsd.org Subject: Re: sysctl(3) and sysctl(8) discrepancies X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 19 Apr 2006 19:47:01 -0000 In the last episode (Apr 19), Mathieu Prevot said: > Hello, > > I have FreeBSD 6.1-RC #27: Wed Apr 19 02:08:00 CEST 2006 amd64 and I have 3 > different outputs about hw.ncpu: > > `sysctl hw.ncpu` gives me: > > 'hw.ncpu: 2' > > > and I have: > > hw.ncpu = 6 > hw.ncpu = 3 > > > with: > > #include > #include > #include > > main() > { > int ncpu[1]; > size_t len; > > len=sizeof(int); > sysctlnametomib("hw.ncpu",ncpu,&len); You want sysctlbyname() here instead. sysctlnametomib() returns a pointer to a mib array that you can pass to the sysctl() function later. Saves having to parse the string every time if you are looking up the same sysctl repeatedly. sysctlbyname("hw.ncpu", &ncpu, &len, NULL, 0); HW_NCPU is the mib number for hw.ncpu if you want to build the mib array manually. -- Dan Nelson dnelson@allantgroup.com