How do I tell valgrind to memcheck forked processes?
23,536
- Valgrind follows forked processes when given the
--trace-children=yes
option. - You should be able to achieve this by using suitable filters.
- No. Valgrind hooks into the module loading code using LD_PRELOAD, so attaching to a running process is not possible.
Related videos on Youtube
Comments
-
Nathan Fellman almost 2 years
I have a process
x
that I want to check for leaks withvalgrind
. The problem is thatx
is run byy
, andy
in turn is run byz
. I can't runx
standalone becausey
andz
setup the environment forx
, such as environment variables, command line switches, files needed byx
etc.- Is there any way I can tell
valgrind
to run onz
but to follow any forks it finds and report them too? - Is there any way I can tell
valgrind
to follow any forks but only report on the process namedx
? - 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!
- Is there any way I can tell
-
Employed Russian over 15 yearsValgrind 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 almost 15 yearswhen using trace-childen, dont you also need to specify --depth otherwise it will stop monitoring forks of forks?
-
mark4o about 14 yearsThere is no
--depth
option;--trace-children=yes
will trace forks of forks and all other descendants. -
user2918201 about 12 yearsAccording 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).