LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices

Reply
 
Search this Thread
Old 02-17-2008, 03:51 AM   #1
Sinedie
Member
 
Registered: Nov 2006
Posts: 71

Rep: Reputation: 15
PHP: How to set memory and time limits for online compiler?


Hello,
I would like to develop an online compiler for competitions running on Linux. I would like to know how can I compile and execute programs submitted within specific memory limit. Would ulimit be adequate or should something more is required to constrain the process to run in the required memory limits? Please help me.

TIA,
-S

Last edited by Sinedie; 02-17-2008 at 03:54 AM.
 
Old 02-17-2008, 07:58 AM   #2
Deleriux
Member
 
Registered: Nov 2003
Posts: 89

Rep: Reputation: 16
I believe there is php limits in php.ini to set the maximum usable memory and execution time of a php application.

Using ulimits would probably be of little use as they only work on a per-shell basis (they effect all the children of a shell). Since you might have a number of processes in the same shell the ulimit method might be skewed.
 
Old 02-18-2008, 05:01 AM   #3
Sinedie
Member
 
Registered: Nov 2006
Posts: 71

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by Deleriux View Post
I believe there is php limits in php.ini to set the maximum usable memory and execution time of a php application.

Using ulimits would probably be of little use as they only work on a per-shell basis (they effect all the children of a shell). Since you might have a number of processes in the same shell the ulimit method might be skewed.
But if I run an executable with PHP, will the child process' memory consumption gets counted? Or is it only the scripts? I am not sure about this..., will try to run it and see...

Thanks for pointing to this Deleriux. The default value for memory_limit is 32MB. So will try to run an executable as a child process and see if it counts it.
 
Old 02-18-2008, 05:17 AM   #4
Sinedie
Member
 
Registered: Nov 2006
Posts: 71

Original Poster
Rep: Reputation: 15
I just checked and it did not prevent the child executable from taking hundreds of MB (instead of 32MB). OTOH, ulimit -v worked from shell, though doesn't seem to work with 'sh -f shell_script_name'.
 
Old 08-16-2008, 07:37 AM   #5
Sinedie
Member
 
Registered: Nov 2006
Posts: 71

Original Poster
Rep: Reputation: 15
I am still stuck with the same problem

I would need to compile and execute a C/C++/Java code from PHP as part of online compiler. Can anyone help me with a safe way of compiling and executing a script? I think chroot-ing apache will solve some problems, plus using SELinux. How could one possibly run an executable from shell using PHP with memory limits?

Thanks in advance for any information.

-S
 
Old 08-16-2008, 08:02 AM   #6
Sinedie
Member
 
Registered: Nov 2006
Posts: 71

Original Poster
Rep: Reputation: 15
I have tested the following shell script that takes a C++ program name and kills it after 5 secs. I would like to know the comments on it:

Code:
        i_file=$1
        pid=$$
        tlimit=$2
        e_file="/var/www/html/san/test/"$pid".exe"
        lock="/var/www/html/san/test/LOCK"

        ulimit -v 1020400

        while [ -f $lock ]
        do
                sleep 1
        done

        touch $lock

        echo c++ $i_file -o $e_file
        c++ $i_file -o $e_file

        $e_file &

        sleep $tlimit

        kill -9 $!
        rm -f $e_file
        rm -f $lock

Last edited by Sinedie; 08-16-2008 at 08:23 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
limits on memory resource bayram Linux - General 3 12-14-2006 11:32 AM
time and memory limits psmech Linux - General 2 02-15-2006 06:07 PM
user account time limits DAChristen29 Linux - Networking 2 12-24-2004 06:00 PM
array size/C++ memory limits for user space programs? thrifteed Programming 4 09-05-2004 04:42 AM


All times are GMT -5. The time now is 11:12 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration