在线评判系统

时间:2012-02-03 18:44:42

标签: c++ web-services compiler-construction

我想创建一些有问题的网络服务并判断系统。用户应该用C ++编写解决方案,然后上传源代码。然后应该编译代码并测试以确定解决方案是否正确(就像TopCoder在您提交代码时所做的那样)。运行解决方案应该有时间和内存限制。是否有一些现成的判断系统可以在Linux上创建这样的服务?

3 个答案:

答案 0 :(得分:4)

您的意思是acm.timus.ru等在线评判系统吗?然后你可以尝试code.google.com上的开源项目,我猜他们使用它here。我在这段代码之前研究了一下:基本上它会阻止一些系统调用并测量花费的时间和内存。详细信息,请查看here

答案 1 :(得分:2)

我使用了DomJudge系统,该系统已准备好进行在线比赛。 http://domjudge.sourceforge.net/

答案 2 :(得分:1)

仅检查内存和时间上限,只需将代码自动添加到项目中。另外,请参阅Limit physical memory per process以了解内存上限。

例如,要检查内存,请添加: (编辑为LINUX示例)

#include "sys/types.h"
#include "sys/sysinfo.h"
#inlcude <stdio.h>
#include <pthread.h>

public long long getMemoryUsage()
{
     sysinfo (&memInfo);
     long long totalVirtualMem = memInfo.totalram; //Total physical memory
}

在Main()中添加一个调用函数的新线程,如下所示:

private const long long MAXMEMORY = 1024; // Memory cap
private const int LIMITAPPLICATION = 100; // 10 seconds
private void TimeLimitToApplication()
{
    //LIMITAPPLICATION represents how many 100ms's must 
    //pass until time limit is reached. 
    while(COUNTER < LIMITAPPLICATION)
    {
        sleep(100);
        /* Include if including code block below
        if(CheckProcessThreadsIsComplete()) break;
        */
        //Check memory usage every 100ms
        if(getMemoryUsage() > MAXMEMORY)
            break;
        COUNTER++;
    }
    pgid = getpgid();
    kill(pgid, 15);
}

您可能还想添加另一项检查以查看是否所有线程都已完成: (我只有一个C#.NET示例,但我相信你可以找到类似的东西。)

public static bool CheckProcessThreadsIsComplete()
{
  Process[] allProcs = Process.GetProcesses();

  foreach(Process proc in allProcs)
  {
     ProcessThreadCollection myThreads = proc.Threads;
     foreach(ProcessThread pt in myThreads)
     {
        //Ignore thread that you started to do time and memory checks
        if(pt.Id == TIMELIMIT_AND_MEMORYCHECK_THREAD_ID) continue;
        if(pt.ThreadState != (ThreadState.Unstarted | ThreadState.Stopped | ThreadState.WaitSleepJoin | ThreadState.Aborted)
            return true; // all threads are not completed

     }
  }
  return false; // all threads are completed
}

并将其添加到TimeLimitToApplication();

中的检查中