I'm not a big C expert, and that's why I ask this (probably) easy question. I got a script written in C, and I'd like to limit the execution time with input.
Like: ./script.c input1 input2 input3 input4
Input4 has to be the time limit in seconds.
In php, it would be something like this:
$_GET['time'] = $time;
max_execution_time($time); or set_time_limit($time)
And then I would run it like this: http://domain.com/script.php?time=60
I think that init_rand(time(NULL)); should work for the time limiting but how can I take the variable from the "GET" (input4)?
May be you can run this program as a child of another program.
if ((pid = fork()) < 0) {
exit(1);
} else if (pid == 0) {
execvp("this prog", argv);
} else {
sleep(atoi(argv[4]);
kill(pid, SIGTERM);
}
Or may be you can use bash scripts to do the job.
./thisprog $1 $2 $3 &
sleep $4
kill $! 2>/dev/null
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With