The attached little shell script attempts to find out the number of
CPUs and print it out.  This might come in handy if someone wants to
print out the number of CPUs in the Subject line of their smoke report
(useful to know for the threads tests: a uniprocessor really doesn't
stress test the threads enough).  Portability testing (and more
portability) of the script are very welcome.

-- 
Jarkko Hietaniemi <[EMAIL PROTECTED]> http://www.iki.fi/jhi/ "There is this special
biologist word we use for 'stable'.  It is 'dead'." -- Jack Cohen
#!/bin/sh

#
# ncpu - display the number of active/enabled/online CPUs
#
# Jarkko Hietaniemi <[EMAIL PROTECTED]>
#
# $Id: ncpu,v 1.7 2002/11/15 16:10:26 jhi Exp $
#

PATH=$PATH:/usr/sbin # for psrinfo, sysctl

uname=`uname`

case "$uname" in
AIX)
        lsdev -C -c processor -S Available|grep -c . # wc -l formats funny
        ;;
*BSD|*bsd|Darwin)
        sysctl -n hw.ncpu
        ;;
HP-UX)  # does this work for non-root users?
        ioscan -fnkC processor|grep -c '^processor'
        ;;
IRIX*) # IRIX, IRIX64
        hinv -c processor|head -1|awk '{print $1}'
        ;;
Linux)
        if test -f /proc/cpuinfo; then
                grep -c '^processor' /proc/cpuinfo
        else
                echo "$0: no /proc/cpuinfo" 2>&1
                exit 1
        fi
        ;;
OSF1|SunOS)
        psrinfo|grep -c on-line
        ;;
*)
        echo "$0: unknown uname '$uname'" 2>&1
        exit 1
        ;;
esac

exit 0

Reply via email to