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.
This commit is contained in:
Kenneth Myhra 2023-05-02 21:04:35 +02:00 committed by Jelle Raaijmakers
parent 449911c286
commit 36c892ae14

View file

@ -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)
}