tags:

views:

193

answers:

1

I need to detect whether my Makefile is running under valgrind (indirectly, using valgrind --trace-children=yes), I know how to do it from C but I have not found a way to do it from a script,

The earlier answers works on Linux only. For Mac OS X I am an going to grep for VALGRIND_STARTUP_PWD in the environment, unless someone has a better idea.

+2  A: 

from a shell:

grep -q '/valgrind' /proc/$$/maps && echo "valgrindage"

This determines if the valgrind preloaded libraries are present in address map of the process. This is reasonably effective, but if you happen to have a non-valgrind related library that shares the '/valgrind' moniker then you will get a false positive (unlikely).

[I changed the grep pattern from vg_preload to /valgrind, as testing on Debian/Ubuntu revealed that the library name was different, while a directory match of valgrind is most likely to succeed.]

Petesh
Neat. Do you know if the name has changed? There are vgpreload entries but no vg_preload on my machine.
This was from valgrind version 3.3.1, There is a good chance that the library name has changed between versions. you might be able to get away with a '/valgrind/' for the grep, providing valgrind is installed into something like /usr/local/lib/valgrind/ ...
Petesh
I just ran valgrind from my ubuntu box and it said 'vgpreload' without the underscore. This may be an ubuntu thing that caused the rename. My original answer was based on a build inside of a Linux From Scratch environment
Petesh
Yes, I have an Ubuntu box too. Thanks.