To check for memory leaks you might like to run the program under Valgrind: http://valgrind.org
To get/set limits from the console/shell there is the ulimit command available.
From inside the program the system calls getrlimit()/setrlimit() provide this functionality.
Another workaround for situations where memory might get tight due to fork()ing would be to use vfork() immediately followed by a call to 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 may be useful in performance-sensitive applications where a child is created which then immediately issues an execve(2).
vfork() differs from fork(2) in that the parent is suspended until the child terminates (either normally, by calling _exit(2), or abnormally, after delivery of a fatal signal), or it makes a call to execve(2). Until that
point, the child shares all memory with its parent, including the stack. The child must not return from the current function or call exit(3), but may call _exit(2).