I'm tring to predict memory leak in an linux c++ programme.
The programme is an network server which fork a lot of sub-process to handle request.
I can get the RSS of the process after it handled one request, and I want to make the process kill itself if it find out that there could be memory leak.
I can make the process kill itself if it's RSS is bigger than an configured value ( like 1GB ), but this seems too simple and this value is also not easy to configure.
I can also make the process kill itself if the RSS is bigger and bigger for N times (like 100), but this seems not proper too, if the process cache some datas.
Is there any memory leak prediction algorithms?
I have googled it, but can't find one.
Thanks.
Sorry for not makeing the question clear.
Actually I'm not trying to find some way to find how the memory leak, I know there is tools like valgrind.
The situation is like this:
The programme I worted is an RPC framework, there is a father process, which will fork lots of sub-processes.
These sub process will run some business logic code which is not written by me and I have no control of these codes.
When these logic codes leak memory, the sub-process will be killed by the os OOM Killer.
But at that point, due to lack of memory, the os will halt for a while (minutes or even more ) or even breakdown and we will have to reboot the system.
I want to avoid this situation by predict the memory leak of the logic codes and make the sub-process kill itself before the OOM Kill do it's job.
And if the sub-process kill itself, the father process will fork another sub-process to run the logic code.
I can get the memory occupied by the sub-process after it handle one request.
So the simplest way is to check if the sub-process occupy too much memory than an pre-configured value (like 1GB), if it is, then make it kill itself.
But this algorithm seems too simple and the value is not easy to configure.
So what I'm finding is an algorithm to predict that if there is memory leak in an process.
Thanks