How to create a CPU spike with a bash command

后端 未结 23 1217
小蘑菇
小蘑菇 2020-11-30 16:11

I want to create a near 100% load on a Linux machine. It\'s quad core system and I want all cores going full speed. Ideally, the CPU load would last a designated amount of

23条回答
  •  鱼传尺愫
    2020-11-30 16:45

    To enhance dimba's answer and provide something more pluggable (because i needed something similar). I have written the following using the dd load-up concept :D

    It will check current cores, and create that many dd threads. Start and End core load with Enter

    #!/bin/bash
    
    load_dd() {
        dd if=/dev/zero of=/dev/null
    }
    
    fulload() {
        unset LOAD_ME_UP_SCOTTY
        export cores="$(grep proc /proc/cpuinfo -c)"
        for i in $( seq 1 $( expr $cores - 1 ) )
          do
        export LOAD_ME_UP_SCOTTY="${LOAD_ME_UP_SCOTTY}$(echo 'load_dd | ')"
      done
            export LOAD_ME_UP_SCOTTY="${LOAD_ME_UP_SCOTTY}$(echo 'load_dd &')"
        eval ${LOAD_ME_UP_SCOTTY}
    }
    
    echo press return to begin and stop fullload of cores
      read
      fulload
      read
      killall -9 dd
    

提交回复
热议问题