Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I tell valgrind to memcheck forked processes?

I have a process x that I want to check for leaks with valgrind. The problem is that x is run by y, and y in turn is run by z. I can't run x standalone because y and z setup the environment for x, such as environment variables, command line switches, files needed by x etc.

  1. Is there any way I can tell valgrind to run on z but to follow any forks it finds and report them too?
  2. Is there any way I can tell valgrind to follow any forks but only report on the process named x?
  3. Is there any way I can tell valgrind to attach to already-running process, the way I can do with gdb?

I don't know if this matters, but I'm running under SuSE64 linux and valgrind-2.4.0.

Thanks!

like image 866
Nathan Fellman Avatar asked Nov 19 '08 11:11

Nathan Fellman


People also ask

Can Valgrind attach to a running process?

Therefore Memcheck does not support eager checking at this time. 5.4. Is it possible to attach Valgrind to a program that is already running? No.

How do I run valgrind faster?

Valgrind doesn't actually execute your code natively - instead it runs it inside a simulator. That's why it's so slow. So, there's no way to make it run faster, and still get the benefit of Valgrind. Your best bet is to set the ulimit so that your program generates a core file when it crashes.

What is valgrind Linux?

Valgrind (/ˈvælɡrɪnd/) is a programming tool for memory debugging, memory leak detection, and profiling. Valgrind. Original author(s) Julian Seward. Developer(s)


1 Answers

  1. Valgrind follows forked processes when given the --trace-children=yes option.
  2. You should be able to achieve this by using suitable filters.
  3. No. Valgrind hooks into the module loading code using LD_PRELOAD, so attaching to a running process is not possible.
like image 169
JesperE Avatar answered Sep 23 '22 11:09

JesperE