projects
/
runfinite.git
/ blobdiff
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
add setting environment variables -> fix GL bug
[runfinite.git]
/
src
/
main.cpp
diff --git
a/src/main.cpp
b/src/main.cpp
index 5b1ca074fb3c2da93178d3357c09b53f9df382fd..3e147b97e4d92056473aec843e43ebab2e35cecb 100644
(file)
--- 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 <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@@
-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;
{
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) );
if( pid == 0)
{
char** newargv = (char**) malloc( sizeof(char*)*(argc-fiarg+1) );
- char* newenv[] = {NULL};
//Copy arguments
for( int i=fiarg; i<argc; i++)
//Copy arguments
for( int i=fiarg; i<argc; i++)
@@
-154,7
+162,7
@@
int main(int argc, char** argv)
//Execute child process
//Execute child process
- execve(newargv[0], newargv,
newenv
);
+ execve(newargv[0], newargv,
envp
);
perror("execve");
return ERR_EXECVE;
}
perror("execve");
return ERR_EXECVE;
}
@@
-172,12
+180,14
@@
int main(int argc, char** argv)
//Nmb of loops=seconds
float loops=0;
//Status flags of child process
//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
{
//Kill the child
- if( loops >= maxtime )
+ if( loops
*ussleep/1e6
>= maxtime )
{
if( argVerbose )
printf("Kill child...\n");
{
if( argVerbose )
printf("Kill child...\n");
@@
-186,15
+196,18
@@
int main(int argc, char** argv)
break;
}
break;
}
- //Sleep a round
- sleep(1);
- loops++;
-
//Test for child
if( waitpid(-1, &status, WNOHANG | WUNTRACED | WCONTINUED) < 0 )
break;
//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++;
+
+ }
}
}