From 36c892ae14598f301cfc355087bed474c3823221 Mon Sep 17 00:00:00 2001 From: Kenneth Myhra Date: Tue, 2 May 2023 21:04:35 +0200 Subject: [PATCH] Meta: Add get_number_of_processing_units() to shell_include.sh This adds the method get_number_of_processing_units() which returns the number of processing units the system has available. --- Meta/shell_include.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Meta/shell_include.sh b/Meta/shell_include.sh index 78aa59e9e59..11da2e1999e 100644 --- a/Meta/shell_include.sh +++ b/Meta/shell_include.sh @@ -57,3 +57,18 @@ FUSE2FS_PATH="$(find_executable fuse2fs)" RESIZE2FS_PATH="$(find_executable resize2fs)" E2FSCK_PATH="$(find_executable e2fsck)" MKE2FS_PATH="$(find_executable mke2fs)" + +get_number_of_processing_units() { + number_of_processing_units="nproc" + SYSTEM_NAME="$(uname -s)" + + if [ "$SYSTEM_NAME" = "OpenBSD" ]; then + number_of_processing_units="sysctl -n hw.ncpuonline" + elif [ "$SYSTEM_NAME" = "FreeBSD" ]; then + number_of_processing_units="sysctl -n hw.ncpu" + elif [ "$SYSTEM_NAME" = "Darwin" ]; then + number_of_processing_units="sysctl -n hw.ncpu" + fi + + ($number_of_processing_units) +}