title: timers in linux in c
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/5540245/loops-timers-in-c">Loops/timers in C</a>  </p>
  </blockquote>
  
  
  
  <p>I've been reading about timers for the last 3 days and I'm unable to find anything useful, I'm trying to understand it in real example, can somebody help me figure out how to setup an alarm for the below program. </p>
  
  <p>How can I set a a timer so that it will send 2 args, one is the array name, and the second one is the number to be deleted, I know the below is not safe in anyway, I'm just trying to understand how use alarms with args to call a function.</p>
  
  <p>please note that the environment is Linux, and also I appreciate any link with a working C example. </p>
  
  <pre><code>#include&lt;stdio.h&gt;
  int delete_from_array(int arg) ;
  
  
      int main()
      {
  
      int a[10000], i, y ;
      //how to set timer here for to delete any number in array after half a second
      for (y=0; y &lt; 100; y++) {
  
  
          for (i=0; i&lt;sizeof(a) / sizeof(int); i++)
              a[i] = i;
      sleep(1);
      printf("wake\n");
      }
  
      }
  
      int delete_from_array(int arg) 
      {
      int i, a[1000], number_to_delete=0;
  
      //number_to_delete = arg-&gt;number;
  
      for (i=0; i&lt;sizeof(a); i++)
          if (a[i] == number_to_delete)
              a[i] = 0;
      printf("deleted\n");
  
      }
  </code></pre>
  
  <p>What I'm trying to do is that I have a hash which has has values to be expired after 1 seconds, so after I insert the value into the hash, I need to create a timer so that it will delete that value after let's say 1 second, and IF I got a response from the server before the that interval (1 second) then I delete the value from the hash and delete the timer, almost like retransmission in tcp </p>