Prashant Singh
Prashant Singh

Reputation: 51

Attach valgrind with daemon and collect logs for each daemon call

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?

Upvotes: 5

Views: 21506

Answers (2)

VarunPandey
VarunPandey

Reputation: 327

For systemd managed daemon, you can change the ExecStart= to run valgrind like following:

ExecStart={valgrind-command-with-flags} /usr/sbin/foo-daemon

Do make sure to redirect the output to a well defined location.

Caution: Daemon running with valgrind could be extremely slow and could potentially not run as expected

Upvotes: 1

FabienRohrer
FabienRohrer

Reputation: 1834

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.

Upvotes: 5

Related Questions