Re: Detecting SMP

From: Mike A. Harris (
Date: Sat Feb 24 2001 - 08:44:26 EST

On Tue, 20 Feb 2001, Burton Windle wrote:

>Hello. Is there a way, when running a non-SMP kernel, to detect or
>otherwise tell (software only; the machine is 2400 miles away) if the
>system has SMP capibilties? Would /proc/cpuinfo show two CPUs if the
>kernel is non-SMP? Thanks!
>(btw, the kernel in question is a stock RH6.2 kernel 2.2.14-5, and yes, I
>know I should update it anyways and that a SMP kernel will run on a UP

Yes, there are several ways. How do you want to know how to do
it, in C, or a bash script? sysconf is one way, parsing
/proc/cpuinfo and /proc/stat is another. Beware though, if you
parse /proc/cpuinfo or stat, it is very different on different
architectures, particularly sparc.

Here is some code which should do it more or less correctly on
any arch:

ncpus=$(egrep -c ^cpu[0-9]+ /proc/stat || :)
[ "$ncpus" = "0" ] && ncpus=1

    Mike A. Harris - Linux advocate - Free Software advocate
          This message is copyright 2001, all rights reserved.
  Views expressed are my own, not necessarily shared by my employer.
if (argc > 1 && strcmp(argv[1], "-advice") == 0) {
    printf("Don't Panic!\n");

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at
Please read the FAQ at

This archive was generated by hypermail 2b29 : Wed Feb 28 2001 - 21:00:07 EST