I want to start a process with a memory limit set (ideally a data segment, stack and heap) My code looks something like
child = fork(); if ( child == 0 ) { ... execv( program, args ); } wait( &status );
and this structure should be a keeper, I do some things with it (redirecting stdin / out, measuring runtime, etc.)
My question is: how can I set a memory limit for a software process and tell my parents if it has been exceeded? A process should not be killed with siggs, I want to know that this process was killed only because of this memory limitation. Or better, is there a way to get the memory usage of this process when it finishes? At the end of the process, I can compare the maximum memory used.
I cannot use valgrind (or something like that) because I cannot slow down the runtime.
source share