Created
October 19, 2016 13:06
-
-
Save dln/23ceda77fbed89b8d4df6541553aa196 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| set -e | |
| libhack=$(mktemp --tmpdir libhack_XXXXX.so) | |
| trap "rm -f ${libhack}" EXIT | |
| gcc -O3 -fPIC -shared -Wl,-soname,libnumcpus.so -o ${libhack} -x c - <<EOF | |
| #include <stdlib.h> | |
| #include <unistd.h> | |
| int JVM_ActiveProcessorCount(void) { | |
| char* val = getenv("_NUM_CPUS"); | |
| return val != NULL ? atoi(val) : sysconf(_SC_NPROCESSORS_ONLN); | |
| } | |
| EOF | |
| LD_PRELOAD=${libhack} _NUM_CPUS=2 "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment