简体   繁体   中英

Online judge system

I would like to create web-service with some problems and judge system. The user should write solution in C++ and then upload the source code. Then code should be compiled and test to determinate if the solution is right(like TopCoder does when you submit your code). There should be time and memory limits for solutions to run. Is there some ready-to-use judge systems to create such a service on Linux?

Do you mean online judge system like acm.timus.ru ? Then you could try open source project on code.google.com and I guess that they use it here . I studied before this code a little bit: basically it prevents some system calls and measures spent time and memory. In detail, have a look at here .

I used DomJudge system which is ready for online competitions. http://domjudge.sourceforge.net/

For just checking memory and time caps, just add the code into their project automatically . Also, see Limit physical memory per process for memory caps as well.

For example, to check memory, add: (EDITED FOR LINUX EXAMPLE)

#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
}

And add a new Thread to their Main() that calls a function as follow:

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);
}

You might also want to add another check to see if all your threads are completed: (I only have a C#.NET sample of this, but I'm sure you could find something similar.)

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
}

And add that to your checks in TimeLimitToApplication();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM