Server crashes when too much memory is allocated

what about using /etc/security/limits.conf to limit the amount of cpu for the user.

Or with:

ulimit -m <size in megabytes>

in the shell, and then executing the process.