//Nmb of loops=seconds
float loops=0;
//Status flags of child process
- int status, w;
+ int status;
+ //100ms granularity
+ const int ussleep=100000;
- do
+ while(true)
{
//Kill the child
- if( loops >= maxtime )
+ if( loops*ussleep/1e6 >= maxtime )
{
if( argVerbose )
printf("Kill child...\n");
break;
}
- //Sleep a round
- sleep(1);
- loops++;
-
//Test for child
if( waitpid(-1, &status, WNOHANG | WUNTRACED | WCONTINUED) < 0 )
break;
- }while( !WIFEXITED(status) );
+ if( WIFEXITED(status) )
+ break;
+
+ //Sleep a round
+ usleep(ussleep);
+ loops++;
+
+ }
}