]> gitweb @ CieloNegro.org - autobuild.git/blobdiff - lib/detectNumCPUs.bash
Split the script to several files.
[autobuild.git] / lib / detectNumCPUs.bash
diff --git a/lib/detectNumCPUs.bash b/lib/detectNumCPUs.bash
new file mode 100644 (file)
index 0000000..7720247
--- /dev/null
@@ -0,0 +1,13 @@
+function detectNumCPUs () {
+    if sysctl -n "hw.ncpu" 2>/dev/null; then
+        # This works for most BSDs.
+        :
+    elif grep -qF processor /proc/cpuinfo 2>/dev/null; then
+        # Linux sucks...
+        grep -cF processor /proc/cpuinfo
+    else
+        echo -n "WARNING: $0 doesn't know how to detect the number of" >&2
+        echo -n "processors on this platform. Assuming we have just one..." >&2
+        echo 1
+    fi
+}