Search code examples
bashsshbenchmarkingmulticore

Disable all but one core via bash command


Is there a way to switch off one of the cores of a dual core machine via a bash command? I am trying to compare the performance of different machines and I want to use only one core in each of the machines. Is there a way to do that? (Note that I am doing this via SSH, so please tell me the options which will work via SSH. I do have root privileges though.)


Solution

  • Here you go:

    root# echo 0 > /sys/devices/system/cpu/cpu1/online
    root# dmesg | tail | grep CPU
    [23164.810371] CPU 1 is now offline
    

    Redirection is done by the shell so if you need to use sudo, run it like this

    $ sudo sh -c 'echo 0 >/sys/devices/system/cpu/cpu1/online'
    

    If you're on a tilera ;)

    root# for i in $(seq 1 99); do echo 0 >/sys/devices/system/cpu/cpu$i/online; done