How do I tell valgrind to memcheck forked processes?

23,536
  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.
Share:
23,536

Related videos on Youtube

Nathan Fellman
Author by

Nathan Fellman

SOreadytohelp

Updated on July 09, 2022

Comments

  • Nathan Fellman
    Nathan Fellman almost 2 years

    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!

  • Employed Russian
    Employed Russian over 15 years
    Valgrind used to use LD_PRELOAD, but doesn't do so in current versions. Your answer to 3. is still correct, but the reason has nothing to do with LD_PRELOAD.
  • bisthebis
    bisthebis almost 15 years
    when using trace-childen, dont you also need to specify --depth otherwise it will stop monitoring forks of forks?
  • mark4o
    mark4o about 14 years
    There is no --depth option; --trace-children=yes will trace forks of forks and all other descendants.
  • user2918201
    user2918201 about 12 years
    According to the man page, this option does not cause valgrind to trace into forks, it causes it to trace into execs. Valgrind always follows forks, but won't follow an exec unless you add this option (is my understanding of the man page).