You can use ulimit to do this (just a wrapper for setrlimit). As an example:
Code:
(ulimit -d 10000 -m 10000 -v 10000; [command])
Make sure to run ulimit within its own script, or run it before cp/etc within its own function, as this is used to set global limits. The -d flag is your data segment size, -m is maximum memory size, and -v is max virtual memory size. Use ulimit -a to see what all can be set.
You can also use cgroups as well, see here for more information:
https://www.kernel.org/doc/Documenta...ps/cgroups.txt
Ninja edit: Thanks to szboardstretcher for reminding me of timeout, almost forgot about that!