Process manipulation questions
Hello!
I have written a small program with the purpose of benchmarking other programs. That is, run them, get execution time, memory usage, report if a program terminated succesfully, if it had an error, and also automatically terminate a program if it exceeds a preset time and memory limit. I have implemented all these functions, however I'm not sure if my approaches are the best ones, even if they do seem to work, so I have a few questions:
How can I efficiently monitor a running process' memory usage (created with CreateProcess())? Right now, after I create the process, I run a thread that uses GetProcessMemoryInfo in a while loop, and compares the memory usage with the preset limit. If it exceeds this limit, it terminates the process and returns. This however seems very inefficent, and it even slows down my program a lot, making it return much higher running times for the launched programs (up to 2 seconds more). So, my question is: is there a better way to terminate a process once it exceeds a preset memory limit and somehow return a message that the termination reason is exceeding the allocated memory? If yes, how?
I have added a Sleep(10) in my while loop, which seemed to cut the slowdown completely, but this seems like a very ugly hack, and I would rather not stick to it.
Second, right now I report "Runtime error" if the process exitcode is not 0. Is there a way to report more precise stuff, as in, make sense of the exit codes returned? Like, exitcode X means division by 0, Y means segmentation fault etc...
Thank you for any help.