0

I have a C++ compiled program (an ELF binary) intended to run forever, similar to an HTTP server. I would like to use Valgrind to analyze the program for any memory leaks. However, Valgrind typically prints its output with the analysis after the program exits. Is there a way to configure Valgrind to periodically print its analysis while the program is still running?

If Valgrind does not support this feature, I'm interested in knowing if there are alternative programs that can achieve this.

The program I'm working with is meant to run as a service on an embedded device. Considering this, even small memory leaks could be problematic if they eventually trigger the Linux OOM Killer, leading to the termination of the program.

The main goal here is to track memory leaks (or other memory corruptions) and record the memory addresses of these violations (so that I can find the origin of these memory violations using disassembly techniques).

I have figured out that there is this answer, which suggests checking the memory usage of a process using its PID and the /proc/PID/smaps file. By using the diff command, I can compare the memory consumption between a specific time and a future time to identify any differences. With that information I could use the GDB core dum gcore -o process then use strings to finish my analysis.

I just wish to know if there is a better way to do that (this seems to me a too much manual process).

Already considered using Valgrind and restricting my service to run for 24 hours, then checking Valgrind's output for any issues. However, I believe that if my program can run intermittently for 24 hours, it is not a guarantee that it will run continuously for years, if you know what I mean.

Lincoln
  • 3
  • 4

0 Answers0