对cpu施加负载
使用stress工具
stress工具./stress --cpu 3使用shell
for i in 1 2 3 4; do while : ; do : ; done & donefor i in {1..4}; do while : ; do : ; done & donepython脚本
from multiprocessing import Pool
def f(x):
# Put any cpu (only) consuming operation here. I have given 1 below -
while True:
x * x
# decide how many cpus you need to load with.
no_of_cpu_to_be_consumed = 3
p = Pool(processes=no_of_cpu_to_be_consumed)
p.map(f, range(no_of_cpu_to_be_consumed))参考
Last updated