X-Git-Url: https://git.sthu.org/?p=runfinite.git;a=blobdiff_plain;f=src%2Fmain.cpp;h=3e147b97e4d92056473aec843e43ebab2e35cecb;hp=5b1ca074fb3c2da93178d3357c09b53f9df382fd;hb=8ec778745d7432e558839c811bab5ff2a188fbed;hpb=12db387ab2607688af53d507482bee77f963e3be diff --git a/src/main.cpp b/src/main.cpp index 5b1ca07..3e147b9 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 @@ -31,7 +40,7 @@ void printUsage(FILE* out, int argc, char** argv) } -int main(int argc, char** argv) +int main(int argc, char* argv[], char* envp[]) { bool argHelp=false; bool argTime=false; @@ -142,7 +151,6 @@ int main(int argc, char** argv) if( pid == 0) { char** newargv = (char**) malloc( sizeof(char*)*(argc-fiarg+1) ); - char* newenv[] = {NULL}; //Copy arguments for( int i=fiarg; i= maxtime ) + if( loops*ussleep/1e6 >= maxtime ) { if( argVerbose ) printf("Kill child...\n"); @@ -186,15 +196,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++; + + } }