From owner-freebsd-smp Sat Feb 27 14: 4:14 1999 Delivered-To: freebsd-smp@freebsd.org Received: from picnic.mat.net (picnic.mat.net [206.246.122.133]) by hub.freebsd.org (Postfix) with ESMTP id ADA6F15183 for ; Sat, 27 Feb 1999 14:04:01 -0800 (PST) (envelope-from chuckr@mat.net) Received: from localhost (chuckr@localhost) by picnic.mat.net (8.9.3/8.8.5) with ESMTP id RAA03001; Sat, 27 Feb 1999 17:02:13 -0500 (EST) Date: Sat, 27 Feb 1999 17:02:12 -0500 (EST) From: Chuck Robey To: Mark Turpin Cc: smp@FreeBSD.ORG Subject: Re: Determining the number of processors? In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-smp@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org On Sat, 27 Feb 1999, Mark Turpin wrote: > > Is there any way, in a program, to find out how many processors > a machine has? picnic:/usr2/chuckr:119 >sysctl machdep.smp_cpus machdep.smp_cpus: 2 There is also sysctl(3) for doing it in C ... not really complicated, #include #include #include int main() { int numcpus = 0; int buflen = 4; int mib[2]; int err_ret = 0; mib[0] = CTL_HW; mib[1] = HW_NCPU; if((err_ret = sysctl(mib, 2, &numcpus, &buflen, NULL, 0)) != 0 ) { perror("Error doing sysctl: "); exit(0); } else printf("sysctl returned %d.\n",numcpus); exit(0); } ----------------------------+----------------------------------------------- Chuck Robey | Interests include any kind of voice or data chuckr@glue.umd.edu | communications topic, C programming, and Unix. 213 Lakeside Drive Apt T-1 | Greenbelt, MD 20770 | I run picnic (FreeBSD-current) (301) 220-2114 | and jaunt (Solaris7). ----------------------------+----------------------------------------------- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-smp" in the body of the message