title: Passing IPC(Instructions/Cycles) continuously to other function or variable
body: <p>I am trying to read the performance counters and get the IPC. I need to use IPC to control few machine specific parameters. I am using shell script to do the same. Please see the code below:</p>
  
  <pre><code>while true
  do 
      retval=./perf periodic -e instructions -e cycles -s 50 -d -m td &amp;
      some_pid=$!
      kill some_pid
      if ["$retval" -gt "0.5"] 
          then
              ***something***
      fi
      sleep 1
  done
  </code></pre>
  
  <p>I am getting following error:</p>
  
  <pre><code>Algorithm.sh[27]: kill: some_pid: arguments must be jobs or process IDs
  Algorithm.sh[27]: periodic: not found
  Algorithm.sh[27]: [: missing ]
  Algorithm.sh[27]: kill: some_pid: arguments must be jobs or process IDs
  Algorithm.sh[27]: [: missing ]
  Algorithm.sh[27]: periodic: not found
  Algorithm.sh[27]: kill: some_pid: arguments must be jobs or process IDs
  Algorithm.sh[27]: [: missing ]
  </code></pre>
  
  <p>Can someone give me some pointers on how to get/return the value from perf instruction. I tried using function and returning the value, but it also failed.</p>
  
  <p>---------<strong>UPDATED</strong>----------</p>
  
  <p>Now I am running following, and one of the problem got solved and one is remaining.</p>
  
  <pre><code>./perf periodic -e instructions -e cycles -s 50 -d -m td &gt; result.txt &amp; 
  </code></pre>
  
  <p>And other one is </p>
  
  <pre><code>while true
  do 
      retval=$(tail -n 1 result.txt)
      echo $retval
      if ["$retval" -gt "0.5"] 
          then
              echo "Hello mate"
      fi
      sleep 1
  done
  </code></pre>
  
  <p>The echo is giving value, but then the if statement is not getting executed. It is giving following:</p>
  
  <pre><code>Algorithm.sh[30]: [: missing ]
  0.302430
  Algorithm.sh[30]: [0.302430: not found
  0.472716
  Algorithm.sh[30]: [0.472716: not found
  0.475687
  Algorithm.sh[30]: [0.475687: not found
  </code></pre>
  
  <p>I looked up the if condition syntax and couldn't spot the mistake. Please help.</p>