Блог пользователя techt

Автор techt, 9 лет назад, По-английски

Greetings

First I would like to say thanks to those answered my previous blog, their answers were very helpful.

Now.. in short I'm making an online judge as a graduation project and so far I have finished almost everything except for one last hurdle which is handling TLE and MLE. My priority right now is TLE.

Sandbox Server Details:
- Ubuntu 12.04 LT 64-bit
- Using XAMPP
- Using AppArmor

So , what I'm doing right now is basically get the source code from a post request and then I proceed to compile and run it using exec and shell_exec commands respectively, everything is working fine so far however I can't figure out how to implement TLE handling mechanism.

Right now I'm testing out some methods to accomplish TLE and to do so I'm running a C program to print out numbers from 1 to 250,000 so.. things I have tried :

1- Using timeout command http://manpages.ubuntu.com/manpages/precise/man1/timeout.1.html It works and kills the process after 1 second when I run it on the terminal just fine and the last number it outputs is about 32k however when I use it within shell_exec() it gives me complete output without killing the process.

2- Using some sleep command associated with a kill $! process , same result as above.
3- Changing daemon user to my current user (as I thought it could be a permission issue), same result as above.
4- Disabling AppArmor and restarting , same result as above.

I also googled a lot, I even skipped meals for it believing "I WILL FIND IT AT THIS VERY NEXT MOMENT!" but I can't seem to figure it out....I really don't want users to nuke infinite loops on the server so......help x_X

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
9 лет назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

For myself I would use the timeout parameter from subprocess.communicate in Python. I use a self-modified version of the Python-written online judge here. It works flawlessly, though runtime is completely dependant on your server.

Also, python itself has a cool library named resource to control resource (memory, stack, output) limits.

I run this as my preexec_fn (in your code below)

def setLimits():
	resource.setrlimit(resource.RLIMIT_STACK,(67108864,67108864))
	resource.setrlimit(resource.RLIMIT_DATA,(67108864,67108864))
	resource.setrlimit(resource.RLIMIT_FSIZE,(52428800,52428800))
	os.setsid()

With all the huge numbers as limits.

»
9 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

in fact, there are some good while simple implements on github such as ACDream's judge,hope this will help you. (Some Chinese in that,you may use google to translate it.)