title: How to control/restrict other process to run for very small amount of time in linux
body: <p>The solution in the above link <a href="https://stackoverflow.com/questions/36901621/blocking-and-resuming-execution-of-an-independent-process-in-linux">blocking-and-resuming-execution-of-an-independent-process-in-linux</a> says, I can use ptrace to achieve my goal.<br>
  I have tried to run run the code from- 
  <a href="https://stackoverflow.com/questions/35311767/how-does-ptrace-work-with-2-different-processes"> how ptrace work between 2 processes</a>
   , but not getting any output.</p>
  
  <p>This is specifically asked to know how to use ptrace to make a program execute only few instructions like in debugger case.</p>
  
  <p><strong>How to use ptrace in following situation to restrict other process to access few instructions?</strong></p>
  
  <p>I have two independent C programs under linux. <strong>Program1</strong> is running in <strong>CPU core-1</strong> and <strong>Program-2</strong> is running in <strong>CPU core-2</strong>.</p>
  
  <p>Program-2 is executing shared library function, func-2, consists of 200 lines of instruction to perform operation (add+shift) on data .</p>
  
  <pre><code>shared library function 
  -------
  func-2()
  {
  // code to perform operation (add+shift) on data
  } 
  --------   
  Program2.
  
  main()
  {
  while(1)
  func-2();
  }
  </code></pre>
  
  <hr>
  
  <pre><code>program1
  
  main()
  {
   while()
   {
  
  
  // ptrace 
  
  // OR
  
  //kill STOP &lt;pid of program2&gt;
      // kill CONT &lt;pid of program2&gt;
  }}
  </code></pre>
  
  <p>I want to restrict program-2 <strong>from inside Program-1 or bash</strong> , so that Program-2 can execute only few instructions or restrict to run for 1-2 microsec, I <strong>can't add any code inside Program2.</strong>
  Program-1 knows PID of program2 and base address of func-2.</p>
  
  <p>I heard about ptrace which can be used to control other process and using ptrace it is possible to restrict process to execute only 1 instruction. For me even restrict process for 1-2 microsec ( 5-10 instructions) will be sufficient.</p>
  
  <p>How can I control Program-2 which is running other CPU core? Any link to relevant documents is highly appreciated. Thanks in advance. 
  I am using gcc under linux.</p>