Skip to content
Related Articles

Related Articles

Improve Article

Why Online Judge Crashes During Competitive Programming Contests?

  • Difficulty Level : Basic
  • Last Updated : 12 Aug, 2021
Geek Week

Geek as you are well aware of coding platforms inclusive of competitive codings such as GeeksforGeeks, CodeChef, Codeforces, atCoder, SPOJ, HackerRank, HackerEarth, and many more where it is supposed to code out there itself by either directly writing on their respective editors or by attaching local editor file such as a sublime editor.


Have you ever wondered how the test cases are getting accessed there or in simpler terms how is our code being getting compiled and run to check for the test cases? On these platforms where competitive programming is aligned online judge acts as a backbone for the code submissions.

Important Disclaimer: Refer to this image to get a better understanding before we proceed further. 

From the above image, it can be clearly perceived that an online adjudicator gathers and runs your code, shows some yield or decision. Is it that basic? No, this entire interaction is very confounded. There are few inconveniences associated with it which are as follows:

  1. Time Limit completion: Your code needed to come out at a certain time. Can we set up a time limit while executing a thread on our OS by default?
  2. Memory Limit completion: Your program would not take all the memory on your CPU. How we can change that as well, any easier way?
  3. Stack Overflow Error: After tracing your program, the system will understand whether the program ran successfully or not. How can we get that information?

Okay, all of the above is almost the complication of the system for checking a program. Though their are some security problems. As users are allowed to submit any sort of code on the web judge, it’s quite obvious that some might submit some malicious code. How malicious?

  • Some code can execute different processes.
  • Some code can investigate your document directory, and get a little information.
  • Some code can run administrative commands.
  • Some code can devour the server’s bandwidth.

And there are numerous facts, that a code can do. And you glaringly don’t need to permit this system do that. So how are we able to put into effect these permission guidelines as well? So geek now you must be wondering how does a web decide to handle the above scenarios, we will be proposing out ways which are as follows below:


There are two ways code sandboxing approaches by which the web decides to handles the above different scenarios 

  1. Lame way
  2. Lengthy historical way

Anyway, the technique to restrict permission and hardware for System’s protection is referred to as Code Sand-Boxing.

Way 1: Lame Way

I even have visible a few online decide initiatives in which the developer attempted to discover the malicious capabilities on a code earlier than executing the code. For example, in case your code is on C++, the decision will first take a look at if there may be any line of code in which the “system” phrase is used. This answer won’t paintings for a diverse reason, as many programming languages doesn’t paintings with inside the identical way. You can generate a characteristic dynamically and get in touch with it in a few programming languages, so filtering won’t paintings in the one’s code. Another thing, what in case you want to print “system” as output? This answer will say that the code is malicious however it isn’t.

Way 2: Lengthy Historical Way

In this approach, maximum the net decide works. And this answer is relevant to Linux primarily based totally system.

Stack Overflow/Runtime Error may be checked via way of means of the go back cost of a program. If it’s far 0, then you may say this system ran successfully, in any other case crashed.

Memory Limit hassle and time limitation limitations can be provided using various Unix-based completely libraries. Some programming language enables this shape of limitations flag through manner of way of default, for example, Java. Memory Limit drawback and time restriction boundaries may be supplied the usage of numerous Unix primarily based totally libraries. Some programming language helps this type of boundaries flag through default, for example, Java.

Directory permission is simple on Linux, you simply create a consumer and allow that consumer for a few directories in addition to a few read/write permission. Then execute an application the usage of that consumer, document listing hassle may be solved. Also, that code can’t run a few administrative commands.

Limiting community skills is likewise viable the usage of a few libraries, for example, Trickle. In this solution, one wants to set up diverse libraries and write diverse codes simply to remedy one safety hole.

Contemporary-day manner is as follows:

All of the above troubles are solved in case you use Docker or box primarily based totally VM (Virtual Machine). You can create a box if you want to have a preliminary memory, with preset community permission, Time restriction for the box. All the hassles can be looked after with the aid of using the VM. Developers simply can be aware of the alternative things. In this solution, the entire judging machine can also additionally appear to be slower than the alternative techniques however absolutely on a massive scale it’s far pretty faster, and manner safer, purifier than every other solution. You can take a look at this GitHub Repo to recognize how docker may be used for judging.

This entire manner of judging is one in all maximum vital a part of an online judge. To enforce judging machine, one wants to apprehend how OS works, additionally how the programming language works. Hope you’ve got were given as a minimum a few know-how approximately the entire manner.

Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :