Date: Sat, 27 Feb 1999 17:02:12 -0500 (EST) From: Chuck Robey <chuckr@mat.net> To: Mark Turpin <mturpin@saturn.spel.com> Cc: smp@FreeBSD.ORG Subject: Re: Determining the number of processors? Message-ID: <Pine.BSF.4.05.9902271637570.68172-100000@picnic.mat.net> In-Reply-To: <Pine.BSF.4.05.9902271625180.61883-100000@saturn.spel.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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 <stdio.h> #include <sys/types.h> #include <sys/sysctl.h> 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.05.9902271637570.68172-100000>