Re: API for detection of multiple CPUs

From: apm (apm35_at_student.open.ac.uk)
Date: 10/30/03


Date: 29 Oct 2003 23:20:32 -0800

David <thunderbolt01@netscape.net> wrote in message news:<f5vnb.50391$e01.126978@attbi_s02>...
> apm wrote:
> > Does anyone know if there is an API for detecting how many CPUs are
> > present? I am after a way of programmatically determining whether or
> > not a spinlock could be used in preference to a pthread mutex.
>
> Possibly something like this?
>
> if [ -x /usr/bin/getconf ]; then
> CPUS=`getconf _NPROCESSORS_ONLN`
> fi
> if test "x$CPUS" = "x" -o "x$CPUS" = "x0"; then
> CPUS=1
> fi

That does the trick on Linux, thanks. Now if only I could find a more
portable way. I need something that will work on Solaris, AIX and HPUX
as well.

-Andrew M.



Relevant Pages

  • Re: API for detection of multiple CPUs
    ... > Does anyone know if there is an API for detecting how many CPUs are ... I am after a way of programmatically determining whether or ...
    (comp.os.linux)
  • Re: API for detection of multiple CPUs
    ... > Does anyone know if there is an API for detecting how many CPUs are ... I am after a way of programmatically determining whether or ...
    (comp.os.linux)
  • API for detection of multiple CPUs
    ... Does anyone know if there is an API for detecting how many CPUs are ... I am after a way of programmatically determining whether or ...
    (comp.os.linux)
  • Re: cpuset and affinity implementation
    ... I have implemented a new api similar to processors sets on solaris. ... allows you to assign processes to sets of cpus and dynamically change ... integrated with jail so you can restrict the cpus any jail is allowed to ... Root set - immutable, all cpus, may be root of jail in which case root ...
    (freebsd-current)
  • Re: cpuset and affinity implementation
    ... I have implemented a new api similar to processors sets on solaris. ... allows you to assign processes to sets of cpus and dynamically change those ... integrated with jail so you can restrict the cpus any jail is allowed to ... a big ULE patch I've been working on. ...
    (freebsd-current)