开发者

Disable all but one core via bash command

开发者 https://www.devze.com 2023-03-13 21:32 出处:网络
Is there a way to switch off one of the cores of a dual core machine via a bash command? I am trying 开发者_Python百科to compare the performance of different machines and I want to use only one core i

Is there a way to switch off one of the cores of a dual core machine via a bash command? I am trying 开发者_Python百科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.)


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


You can set the affinity of the various commands you run, in order to force them to be scheduled on a single core.

0

精彩评论

暂无评论...
验证码 换一张
取 消