Skip to content

Commit 91c477f

Browse files
committed
Added cpu_count().
1 parent 07f57ac commit 91c477f

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

share/ruby-install/system.sh

+19
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,25 @@ function detect_downloader()
9393
esac
9494
}
9595

96+
#
97+
# Gets the number of CPU cores.
98+
#
99+
function cpu_count()
100+
{
101+
local count
102+
103+
case "$os_platform" in
104+
Darwin|*BSD)
105+
count="$(sysctl -n hw.ncpu)"
106+
;;
107+
*)
108+
count="$(getconf _NPROCESSORS_ONLN || grep -c ^processor /proc/cpuinfo)"
109+
;;
110+
esac
111+
112+
echo -n "$count"
113+
}
114+
96115
detect_os
97116
detect_sudo
98117
detect_package_manager

test/system-tests/cpu_count_test.sh

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
. ./test/helper.sh
2+
. ./share/ruby-install/system.sh
3+
4+
function test_cpu_count()
5+
{
6+
assertTrue "did not return a number > 0" '(( $(cpu_count) > 0 ))'
7+
}
8+
9+
SHUNIT_PARENT=$0 . $SHUNIT2

0 commit comments

Comments
 (0)