title: How to start and kill a process (command shell ) inside a c program?
body: <p>I am using arduino to store some data from a thermocouple to the laptop ( OSX ). I want to use the stored data on a c program but i have some doubts.</p>
  
  <p>i have this little example:</p>
  
  <pre><code>include &lt;stdio.h&gt;
  include &lt;stdlib.h&gt;
  
  
  int main (void)
  
  {
      int a;
      a=fork();
      if(a==0)
      {
      system("cat /dev/cu.usbmodem1a21 - 9600 &gt;&gt; num.txt");
      }
  
      return 0;
  }
  </code></pre>
  
  <p>I am trying to redirect the serial ( arduino ) to some file, so i use <code>fork</code> to duplicate the process and run the command while the code is still under execution. However this is a dirty solution because i need to kill the process manually using the console. I want to know if there is a way to kill the process using c code inside the same program.</p>
  
  <p>Thanks in advance.</p>
  
  <p>ps: i have tried using getpid() and kill the process, but again i think is a dirty solution. </p>