-
Notifications
You must be signed in to change notification settings - Fork 0
/
proclimit.sh
executable file
·60 lines (49 loc) · 1.48 KB
/
proclimit.sh
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env sh
##
# When this script is invoked inside of a zone:
#
# This script returns a number representing a very conservative estimate of the
# maximum number of processes or threads that you want to run within the zone
# that invoked this script. Typically, you would take this value and define a
# multiplier that works well for your application.
#
# Otherwise:
# This script returns the number of cores reported by the OS.
# If we are on a LX Brand Zone calculation value using utilities only available in the /native
# directory
if [ -d /native ]; then
PATH=$PATH:/native/sbin:/native/usr/bin:/native/sbin
fi
KSH="$(which ksh93)"
PRCTL="$(which prctl)"
if [ -n "${KSH}" ] && [ -n "${PRCTL}" ]; then
CAP=$(${KSH} -c "echo \$((\$(${PRCTL} -n zone.cpu-cap -P \$\$ | grep privileged | awk '{ print \$3; }') / 100))")
# Always show at least one processor
if [ ${CAP} -lt 1 ]; then
echo 1
exit 0
fi
# If there is no cap set, then we will fall through and use the other functions
# to determine the maximum processes.
if [ -n "${CAP}" ]; then
$KSH -c "echo \$((ceil(${CAP})))"
exit 0
fi
fi
# Linux calculation if you have nproc
if [ -n "$(which nproc)" ]; then
nproc
exit 0
fi
# Linux more widely supported implementation
if [ -f /proc/cpuinfo ] && [ -n $(which wc) ]; then
grep processor /proc/cpuinfo | wc -l
exit 0
fi
# OS X calculation
if [ "$(uname)" == "Darwin" ]; then
sysctl -n hw.ncpu
exit 0
fi
# Fallback value if we can't calculate
echo 1