summaryrefslogtreecommitdiff
path: root/mk/detect-cpu-count.sh
blob: abc47387d16d113a0dd39affc465e15893e6df47 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/bin/sh

detect_cpu_count () {
    if [ "$CPUS" = "" ]; then
        # Windows standard environment variable
        CPUS="$NUMBER_OF_PROCESSORS"
    fi

    if [ "$CPUS" = "" ]; then
        # Linux
        CPUS=`getconf _NPROCESSORS_ONLN 2>/dev/null`
    fi

    if [ "$CPUS" = "" ]; then
        # FreeBSD
        CPUS=`getconf NPROCESSORS_ONLN 2>/dev/null`
    fi

    if [ "$CPUS" = "" ]; then
        # nothing helped
        CPUS="1"
    fi
}

detect_cpu_count
echo "$CPUS"