To check for memory leaks, you can run the program under Valgrind: http://valgrind.org
To get / set restrictions from the console / shell, the ulimit command is available.
Inside the program, the system calls getrlimit() / setrlimit() provide this functionality.
Another workaround for situations where memory might become hard due to fork() ing would be to use vfork() immediately after calling a member of the exec*() family of functions.
From man vfork :
vfork () is a special case of clone (2) . It is used to create new processes without copying the page tables of the parent process. It can be useful in applications with a high degree of sensitivity, where a child is created, which then immediately issues execve (2) .
vfork () differs from fork (2) in that the parent object is paused until the child completes (either fine by calling _exit (2) or abnormally after sending a fatal signal), or it calls execve (2) . Prior to this point, the child shares all memory with its parent, including the stack. The child should not return from the current function or call exit (3) , but can call _exit (2) .
source share