[CentOS] Limit RAM used by a perl script
Paul Bijnens
paul.bijnens at xplanation.com
Mon Jul 20 20:23:38 UTC 2009
On 07/20/2009 05:28 PM, Sean Carolan wrote:
> I have a perl script which runs from a cron job. How would you limit
> the amount of RAM that this script is allowed to consume? Is there a
> ulimit setting that will accomplish this? If so does ulimit have to
> be run each time the script is run, or is there a way to set it
> permanently?
First, install the perl module BSD::Resource
yum install perl-BSD-Resource
Then use it in your program like:
#!/usr/bin/perl
use BSD::Resource;
setrlimit(RLIMIT_VMEM, 1_000_000, 1_000_000);
# rest of the program that is limited to 1MByte now
--
Paul
More information about the CentOS
mailing list