-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathos-detect.c
More file actions
39 lines (35 loc) · 746 Bytes
/
os-detect.c
File metadata and controls
39 lines (35 loc) · 746 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <sys/time.h>
#include <sys/resource.h>
#include <unistd.h>
#include <signal.h>
#include <stdio.h>
#include <assert.h>
int terminate;
struct rusage rusage;
void timeout (int signal)
{
assert (signal == SIGXCPU);
assert (getrusage (RUSAGE_SELF, &rusage) == 0);
terminate = 1;
}
void solve (void)
{
int seconds;
seconds = rusage.ru_utime.tv_sec;
if (rusage.ru_utime.tv_usec >= 500000)
seconds++;
if (seconds > 2)
printf ("-DLINUX_HACK");
}
int main (void)
{
struct rlimit rlimit;
terminate = 0;
signal (SIGXCPU, timeout);
rlimit.rlim_cur = 2;
rlimit.rlim_max = RLIM_INFINITY;
setrlimit (RLIMIT_CPU, &rlimit);
while (terminate == 0);
solve ();
return (0);
}