title: Bash script: CPU stress test while watching clock speed
body: <p>I am totally new to this forum and also new to bash, so please bear with me :).</p>
  
  <p>I would like to write a bash script to conduct a CPU stress test while observing the clock speed. Therefore, I have done the following:</p>
  
  <p>1.) For the CPU stress test, I have created a script named "bernoulli" with the following code:</p>
  
  <pre><code>#!/bin/bash
  # argument 1: n
  
  function bernoulli() 
  { 
      if (( $1 &lt; 3 ))
      then
          echo 1
      else
          echo $(( $(bernoulli $(( $1 - 1 ))) + $(bernoulli $(( $1 - 2 ))) ))
      fi
  }
  bernoulli $1
  </code></pre>
  
  <p>2.) I have figured out that by using the "timeout" command I can kill a task after a specified time. For example,</p>
  
  <pre><code>timeout 30s ./bernoulli 35
  </code></pre>
  
  <p>starts a task calculating the 35th bernoulli number and the task is killed after 30 seconds.</p>
  
  <p>3.) I also found out that by typing</p>
  
  <pre><code>timeout 30s watch grep \"cpu MHz\" /proc/cpuinfo
  </code></pre>
  
  <p>I can watch the clock speed of my cores (updated every 2 seconds) for 30 seconds (at which point "timeout 30s" kills this task).</p>
  
  <p><strong>What I want:</strong> I would like to do the above stress test and simultaneously observe the clock speed. In other words, I would somehow run the two commands</p>
  
  <pre><code>timeout 30s ./bernoulli 35
  timeout 30s watch grep \"cpu MHz\" /proc/cpuinfo
  </code></pre>
  
  <p>"at the same time". I hope I could make it clear what I would like to achieve. Can anyone help with my issue? Thanks a lot for every comment!</p>