From 505431fedca08f25a4cd36f69f8048dd8d4e70a2 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 21 Jun 2024 00:00:10 +0500 Subject: [PATCH] add TL support --- runner/runner.go | 6 +++--- starter/ns_exec.c | 2 -- starter/starter.c | 43 ++++++++++++++++++++++++++++++++++++------- 3 files changed, 39 insertions(+), 12 deletions(-) diff --git a/runner/runner.go b/runner/runner.go index b520f13..397ef91 100644 --- a/runner/runner.go +++ b/runner/runner.go @@ -83,7 +83,7 @@ func Init() error { func IsolatedRun(command []string,core int) { var runId string - for i:=0;i #include #include +#include +#include + #include "util.h" struct params { @@ -21,18 +24,35 @@ struct params { struct limits { size_t memory; int core; + int time; +}; + +struct killparams{ + int time; + int pid; }; #include "ns_exec.c" #include "cgroup_prepare.c" +static int killafter(void *arg) { + //die when parent dies + if (prctl(PR_SET_PDEATHSIG, SIGKILL)) die("cannot PR_SET_PDEATHSIG for child process: %m\n"); + struct killparams* params = (struct killparams*) arg; + struct timespec tw={params->time/1000,((params->time)%1000)*1000000}; + struct timespec tr; + nanosleep(&tw,&tr); + kill(params->pid,SIGKILL); +} + //const size_t STACK_SIZE=1000000; #define STACK_SIZE 1000000 static char nmstack[STACK_SIZE]; +static char killstack[STACK_SIZE]; static void parse_args(int argc, char **argv, struct params *params,struct limits *limits){ - if (argc < 5) { - printf("usage:\n starter "); + if (argc < 6) { + printf("usage:\n starter