[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Limit memory consumption of an ad hoc process



On Mon, Jul 05, 2021 at 11:01:25PM -0400, The Wanderer wrote:
> On 2021-07-05 at 22:42, Victor Sudakov wrote:
> 
> > Greg Wooledge wrote:
> 
> >> And in any case, when you test this stuff, use the subshells.  
> > 
> > Well, my goal is to find a way to limit programs run from cron, PHP's
> > proc_open() etc., not from the interactive shell. What would you advise?
> 
> Is there any reason to think that the ulimit approach wouldn't work in
> that type of context, as well as when invoked from within a shell?

Depends on how the cron job is set up.  If the cron job never calls
bash (but rather, sh) then you can't use bash's ulimit.

Likewise, I would guess that PHP's proc_open() calls /bin/sh, not bash,
but you'd have to ask a (more experienced) PHP user.

I advised using subshells during testing because you don't want to
irrevocably cripple the shell you're using to launch the tests, as the
OP did earlier.  Once you've screwed up your interactive shell, you have
to throw it away and start over, which is a pain in the ass.

> > The equivalent of FreeBSD's `/usr/bin/limits` wrapper seems to be
> > `/usr/bin/prlimit` but I'm really at a loss what limit to specify for
> > testing (the equivalent of `ulimit -v`). Should be RLIMIT_AS but --as 
> > crashes prlimit:
> > 
> > $ prlimit --as=1048576 /bin/ls
> > /bin/ls: error while loading shared libraries: libselinux.so.1: failed to map segment from shared object

Sounds like you set it too low.  Remember, setrlimit(2) and prlimit(2)
say that RLIMIT_DATA is specified in bytes.  This is not the same as
bash's ulimit.


Reply to: