malloc question

Robert Love rml@ximian.com
Mon Apr 26 17:16:00 GMT 2004


On Mon, 2004-04-26 at 18:56 +0200, Sebastien Decugis wrote:

> The problem is that my process is killed when no memory is left. Is that
> a wanted behavior? The posix standard requires the function to return
> NULL and set errno to ENOMEM. Is this behavior dependent on my linux
> distribution (RH9)?

This is the intentional behavior of Linux.

malloc() does return ENOMEM upon memory failure.  Set your SIZEBLK to a
larger stride and you should see it.  You just do not see the error in
your case because the Linux kernel's Out Of Memory (OOM) killer killed
your process first.

> A last question: Does anybody knows a way to go near memory limit
> without being killed?

If your application has the CAP_SYS_RAWIO capability, it is sent SIGTERM
instead of SIGKILL.  So you can catch the SIGTERM and respond.

But the real answer is do not consume all of the memory in the system.

As Uli would say, this email is off-topic for this list, BTW.

	Robert Love




More information about the Libc-alpha mailing list