在多处理器的linux机器上,编写程序使cpu利用率维持在固定的比率上

固定cpu使用率程序

public class Test{
    public static void main(String[] args) throws InterruptedException {
        while (true){
            long start = System.currentTimeMillis();
            long end = System.currentTimeMillis();
            //占用600ms
            while (end - start < 600){
                end = System.currentTimeMillis();
            }
            //休息400ms,cpu使用率大概60%
            Thread.sleep(400);
        }
    }
}

程序绑定在多个cpu处理器上执行

#!/bin/bash
# 8个cpu
for((j=0;j<8;j++))
do
nohup java Test &

pid=$!
echo $pid
taskset -cp $j $pid
done

top命令查看

输入top后,输入1
linux机器上实现占用固定cpu使用率,并将程序绑定到固定cpu上

相关文章:

  • 2022-12-23
  • 2022-02-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-22
  • 2021-06-17
猜你喜欢
  • 2021-05-24
  • 2021-10-29
  • 2022-01-06
  • 2021-11-21
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案