X-Git-Url: https://git.sthu.org/?a=blobdiff_plain;f=src%2Fmain.cpp;h=c4648804283ad1d83e6a8990ddb1db6f58320a6a;hb=2bbed9db2dd1d71e0a0a18465dca157643e84f61;hp=5b1ca074fb3c2da93178d3357c09b53f9df382fd;hpb=12db387ab2607688af53d507482bee77f963e3be;p=runfinite.git diff --git a/src/main.cpp b/src/main.cpp index 5b1ca07..c464880 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,3 +1,12 @@ +/** + * shuber, 2008-04-24 + * + * Little hack to let a process run only a specific amount of time. If process + * has not finished until that amount of time it is killed. + * + */ + + #include #include #include @@ -172,12 +181,14 @@ int main(int argc, char** argv) //Nmb of loops=seconds float loops=0; //Status flags of child process - int status, w; + int status; + //granularity + const int ussleep=25000; - do + while(true) { //Kill the child - if( loops >= maxtime ) + if( loops*ussleep/1e6 >= maxtime ) { if( argVerbose ) printf("Kill child...\n"); @@ -186,15 +197,18 @@ int main(int argc, char** argv) 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++; + + } }