Skip to content

Instantly share code, notes, and snippets.

@blazejhanzel
Created December 13, 2021 21:07
Show Gist options
  • Save blazejhanzel/75a008a1f1f4b00dc29c6f4343d9309a to your computer and use it in GitHub Desktop.
Save blazejhanzel/75a008a1f1f4b00dc29c6f4343d9309a to your computer and use it in GitHub Desktop.
Simple bash program for disabling some cpu cores
#!/bin/bash
# USING
# chmod +x cores.sh
# ./cores.sh x
# where x is a number of cores you want to have active, all others will be disabled
# CONFIG
coresCount=16 # write your number of cores (threads)
# PROGRAM
let endCore=$coresCount-1
if [ $1 -lt 1 ]
then
echo "At least one core must be active"
exit 0
fi
let range=$1-1
for x in $(eval echo {1..$range})
do
echo 1 > "/sys/devices/system/cpu/cpu$x/online"
done
if [ $1 -gt $endCore ]
then
echo "All enabled"
exit 0
fi
for x in $(eval echo {$1..$endCore})
do
echo 0 > "/sys/devices/system/cpu/cpu$x/online"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment