Linux issues on setting a timer function
        Posted  
        
            by 
                laura
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by laura
        
        
        
        Published on 2013-11-02T15:44:56Z
        Indexed on 
            2013/11/02
            21:54 UTC
        
        
        Read the original article
        Hit count: 359
        
linux
I am creating a process with 2 children, 1 of the children is responsible to read questions (line by line from a file), output every question and reading the answer, and the other one is responsable to measure the time elapsed and notify the user at each past 1 minute about the remaining time. My problem is that i couldn't find any useful example of how i can make this set time function to work. Here is what i have tried so far. The problem is that it outputs the same elapsed time every time and never gets out from the loop.
#include<time.h>
#define T 600000
int main(){
  clock_t start, end;
  double elapsed;
  start = clock();
  end = start + T;
  while(clock() < end){
     elapsed = (double) (end - clock()) / CLOCKS_PER_SEC;
     printf("you have %f seconds left\n", elapsed);
     sleep(60);
  }
  return 0;
}
© Stack Overflow or respective owner