Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do memory check on a daemon program?

I have written a C++ application, that runs forever until terminated manually. It monitors other important applications. As a result my Daemon application should not go down. Keeping that in mind, I want to see if there are any memory leaks in my application. I used valgrind but since this application keeps running forever the valgrind does not exit. if I do a control - C then I don't get complete info from the valgrind logfile.

Is there a tool that can do what Valgrind does?

like image 748
Alwin Doss Avatar asked Feb 14 '12 11:02

Alwin Doss


1 Answers

I believe you can connect gdb to a running valgrind process, and instruct it to run a leak check explicitly.

I haven't tried this, just seen it in the docs.

In case of link breakage:

Connecting GDB to a Valgrind gdbserver

$ valgrind --tool=memcheck --vgdb=yes --vgdb-error=0 ./prog

(the error parameter is the number of errors before the gdbserver becomes active: zero means it starts running right away).

Then start gdb on your program and connect to the remote target

$ gdb ./prog
(gdb) target remote | vgdb

and to trigger the check

(gdb) monitor leak_check full reachable any

See your docs or the linked ones for full details.

like image 167
Useless Avatar answered Oct 01 '22 05:10

Useless