mirror of
https://github.com/renbaoshuo/S2OJ.git
synced 2024-11-08 13:38:41 +00:00
chore(judger): add runp::double_to_itimerval
This commit is contained in:
parent
1e63154574
commit
d7aea4cbbc
@ -1,3 +1,4 @@
|
||||
#include <cmath>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
@ -7,6 +8,7 @@
|
||||
#include <filesystem>
|
||||
#include <exception>
|
||||
#include <stdexcept>
|
||||
#include <sys/time.h>
|
||||
|
||||
#define UOJ_GCC "/usr/bin/gcc-11"
|
||||
#define UOJ_GPLUSPLUS "/usr/bin/g++-11"
|
||||
@ -388,6 +390,23 @@ namespace runp {
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
itimerval double_to_itimerval(const double &tl) {
|
||||
struct itimerval val;
|
||||
|
||||
long tl_sec = (long)tl;
|
||||
long tl_usec = (long)((tl - floor(tl)) * 1000 + 100) * 1000;
|
||||
|
||||
if (tl_usec >= 1'000'000l) {
|
||||
tl_sec++;
|
||||
tl_usec -= 1'000'000l;
|
||||
}
|
||||
|
||||
val.it_value = {tl_sec, tl_usec};
|
||||
val.it_interval = {0, 100 * 1000};
|
||||
|
||||
return val;
|
||||
}
|
||||
}
|
||||
|
||||
namespace runp::interaction {
|
||||
|
@ -202,15 +202,7 @@ void set_limit(int r, int rcur, int rmax = -1) {
|
||||
}
|
||||
|
||||
void set_user_cpu_time_limit(double tl) {
|
||||
struct itimerval val;
|
||||
long tl_sec = (long)tl;
|
||||
long tl_usec = (long)((tl - floor(tl)) * 1000 + 100) * 1000;
|
||||
if (tl_usec >= 1'000'000l) {
|
||||
tl_sec++;
|
||||
tl_usec -= 1'000'000l;
|
||||
}
|
||||
val.it_value = {tl_sec, tl_usec};
|
||||
val.it_interval = {0, 100 * 1000};
|
||||
itimerval val = runp::double_to_itimerval(tl);
|
||||
setitimer(ITIMER_VIRTUAL, &val, NULL);
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
@ -15,7 +14,6 @@
|
||||
#include <sys/stat.h>
|
||||
#include <sys/resource.h>
|
||||
#include <sys/user.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/prctl.h>
|
||||
#include <fcntl.h>
|
||||
#include <argp.h>
|
||||
|
Loading…
Reference in New Issue
Block a user