preda2or's blog

By preda2or, history, 2 months ago, In English,

Many users who use sublime text to code in C++ might have faced the infinite loop problem in which the system freezes and the only way out is to restart the machine. If this happens during an ongoing contest it wastes a lot of time. I have a permanent fix for this problem which will safeguard the program from accidentally running into infinite loop.

Sublime C++14 build with timeout : LINK

You can test the above build by running this code.

#include <bits/stdc++.h>   
using namespace std;   

int main() {   
    ios::sync_with_stdio(0);   
    cin.tie(0);   
   
    #ifndef ONLINE_JUDGE   
    freopen("input.txt", "r", stdin);   
    freopen("output.txt", "w", stdout);   
    #endif   
    
    while (true) {   
        cout << "Hello World\n";   
    }   
        
}   

Alternative C++14 Build which will take input from input.txt and store output in output.txt files with timeout: LINK

You can test the above build by running this code.

#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    while (true) {
        cout << "Hello World\n";
    }
    
}

This Sublime build will stop executing the program if it's execution time goes more than 0.5s, thus preventing the system freeze. Usually when we run a sample test in our local machine this limit of 0.5s is more than enough. You can set the timeout to a higher value. 0.5s works fine in my machine.

I hope some users might find this useful.

P.S — I have tried these builds in linux(Ubuntu).

 
 
 
 
  • Vote: I like it  
  • +11
  • Vote: I do not like it  

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by preda2or (previous revision, new revision, compare).

»
2 months ago, # |
  Vote: I like it -17 Vote: I do not like it

jaake aaram kar bhai , kitna code karega ! sublime problem karta hai to codeblocks ya eclipse use kar.

Nahi to Clion .

»
2 months ago, # |
  Vote: I like it +2 Vote: I do not like it

Nice! I love this post!

»
5 weeks ago, # |
  Vote: I like it +6 Vote: I do not like it

Nice, it helped me a lot :) though you don't have to restart your machine , you can kill that process through terminal using kill command.

step 1 : use 'top' command to see the process id

step 2 : use 'kill pid' command to kill that process(replace pid with process id you found in step 1)

it is similar to task manager in windows :p

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Well i knew this method but my machine is low on storage memory. So I had to do it really fast otherwise the size of the ouptut file (in case the code is printing something) became so large that the entire system became unresponsive.