Skip to content

Instantly share code, notes, and snippets.

@upsuper
Created December 28, 2012 04:43
Show Gist options
  • Select an option

  • Save upsuper/4394569 to your computer and use it in GitHub Desktop.

Select an option

Save upsuper/4394569 to your computer and use it in GitHub Desktop.
Switch number of CPU cores in Linux
#!/bin/bash
cat /proc/cpuinfo | grep processor | wc -l
#!/bin/bash
cpus_dir="/sys/devices/system/cpu"
for cpu in $(ls "$cpus_dir" | grep 'cpu[0-9]\+')
do
cpu_online="$cpus_dir/$cpu/online"
if [[ -e "$cpu_online" && $(cat $cpu_online) = 0 ]]
then
echo 1 > "$cpu_online"
fi
done
#!/bin/bash
cpus_dir="/sys/devices/system/cpu"
for cpu in $(ls "$cpus_dir" | grep 'cpu[0-9]\+')
do
cpu_online="$cpus_dir/$cpu/online"
if [[ -e "$cpu_online" && $(cat $cpu_online) = 1 ]]
then
echo 0 > "$cpu_online"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment