title: C: Threads to replace this?
body: <p>I'm doing a program, written in C for my Raspberry Pi, to turn on and off some lights depending on whether it's connected or not to the Internet.</p>
  
  <p>The code i finished and works as i want it to is this:</p>
  
  <pre><code>int doPing() {
    int stat = system("ping -c 1 google.com");
    return stat;
  }
  
  int main() {
    int status;
    int prev_status, isdif;
  
    status = doPing();
    if(status==0)
      system("sudo /home/pi/goingWellBlink &amp;");
    else
      system("sudo /home/pi/errorBlink &amp;");
  
    prev_status = status;
  
    for(;;) {
      status=doPing();
  
      if(status!=prev_status)
        isdif=1;
      else
        isdif=0;
  
      if(isdif &amp;&amp; status==0) {
        system("sudo pkill errorBlink &amp;");
        system("sudo /home/pi/goingWellBlink &amp;");
      }
      if(isdif &amp;&amp; status!=0) {
        system("sudo pkill goingWellBlink &amp;");
        system("sudo /home/pi/errorBlink &amp;");
      }
  
      prev_status=status;
      sleep(10);
    }
  
    return 0;
  }
  </code></pre>
  
  <p>Where <code>errorBlink</code> and <code>goingWellBlink</code> are programs I have already compiled that run in an infinite loop, doing some different light sequence each.</p>
  
  <p>Basically, the main starts asking for the return status of ping, and starts one of the light sequences based on that. That light sequence won't change unless a change in the return status of ping is detected. </p>
  
  <p>For portability purposes, and not depending on two files being exactly there, I want to insert in the code, <code>errorBlink</code> and <code>goingWellBlink</code> as void functions and do this same code but with threads. Instead of starting an external program, starting a thread with the light sequence, how could I achieve this?</p>