Killing a process which ran for a lot of time or is using a lot of memory

Posted by Vedant Terkar on Super User See other posts from Super User or by Vedant Terkar
Published on 2014-01-12T08:55:01Z Indexed on 2014/05/31 21:34 UTC
Read the original article Hit count: 178

Filed under:
|
|
|

I am not sure whether this question belong to Stack Overflow or here, but here we go.

I am designing a online 'C' compiler, which will compile and invoke the program if compilation succeeded.

So here is code which I am using for that:

$str=shell_exec("gcc path/to/file.c -o path/to/file.exe 2>&1");
    if(file_exists("path/to/file.exe")){
        $res=shell_exec("path/to/file.exe <inputfile 2>&1");
        echo $res;
}

This Seems to work fine with simple program files. But When file.c That is the source code entered contains Infinite loop then This script crashes the server and utilizes a lot of memory and time.

So here is my question:

  • Is There any way to detect for how much time does the process file.exe is Running?
  • How Much Space is Utilized by that process that is file.exe?
  • Is There any way to kill the process file.exe if space and time utilization increases beyond certain limit?
  • That Mean if we allocate time of 2.5sec and space of 40Mb at max for that process file.exe and if any one of those 2 constraints is violated then we should display appropriate error message to client

Is it possible?

I am Using WAMP (Windows 7).

© Super User or respective owner

Related posts about command-line

Related posts about php