For Programmers: Free Programming Magazines  


Home > Archive > Unix Programming > August 2005 > Determine number of CPUs









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Determine number of CPUs
Gianni Mariani

2005-08-16, 5:05 pm


Is there any portable way to determine the number of CPUs running ? Or
perhaps if the machine is SMP or not.

On Linux, the only thing I can think of is reading /proc/cpuinfo !

G
Rich Teer

2005-08-16, 5:05 pm

On Tue, 16 Aug 2005, Gianni Mariani wrote:

> Is there any portable way to determine the number of CPUs running ? Or
> perhaps if the machine is SMP or not.


Which version of UNIX? With Solaris you can use sysconf (_SC_NPROCESSORS_ONLN)
for the number of online processors and sysconf (_SC_NPROCESSORS_CONF) to see
how many CPUs are installed.

--
Rich Teer, SCNA, SCSA, OpenSolaris CAB member

President,
Rite Online Inc.

Voice: +1 (250) 979-1638
URL: http://www.rite-group.com/rich
Maxim Yegorushkin

2005-08-17, 4:07 am

Gianni Mariani wrote:
> Is there any portable way to determine the number of CPUs running ? Or
> perhaps if the machine is SMP or not.
>
> On Linux, the only thing I can think of is reading /proc/cpuinfo !


<bits/confname.h> from FC4:

/* Values according to POSIX 1003.1c (POSIX threads). */

#define _SC_NPROCESSORS_CONF _SC_NPROCESSORS_CO
NF
#define _SC_NPROCESSORS_ONLN _SC_NPROCESSORS_ON
LN

Gianni Mariani

2005-08-17, 9:14 am

Rich Teer wrote:
> On Tue, 16 Aug 2005, Gianni Mariani wrote:
>
>
>
>
> Which version of UNIX? With Solaris you can use sysconf (_SC_NPROCESSORS_ONLN)
> for the number of online processors and sysconf (_SC_NPROCESSORS_CONF) to see
> how many CPUs are installed.
>


Perfect !

Thanks to all that replied.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com