Attach valgrind with daemon and collect logs for each daemon call

Prashant Singh picture Prashant Singh · Nov 6, 2014 · Viewed 12.6k times · Source

I have a client server system, completely written in c++. server runs as /etc/init.d/serverd with start/stop options. Client.exe executes any command as client.exe --options. With each client call, daemon hits. I want to attach valgrind with /etc/init.d/serverd to detect leak. I tried below options but failed.

/usr/local/bin/valgrind --log-file=valgrind_1.log -v --trace-children=yes --leak-check=full --tool=memcheck --vgdb=yes --vgdb-error=0 /etc/init.d/ serverd start

Each time it fails to attached with daemon.

What we want is to attach valgrind with daemon at starting time [ the exact point is , I will stop daemon , attach valgrind with it and then start it again ] so that each time , execution of client.exe --options, logs should be generated for daemon in --log-file=valgrind_1.log

Does anyone have any idea about how to do the same?

Answer

FabienRohrer picture FabienRohrer · Nov 6, 2014

It seems not possible to attach valgrind to an existing process: http://valgrind.org/docs/manual/faq.html#faq.attach

It seems to me the best practice is to kill the daemon process, and run by yourself the executable in valgrind.