How can I tell if under valgrind is being executed in a makefile or a shell script?

I need to determine if my Makefile works under valgrind (indirectly, using valgrind --trace-children = yes), I know how to do it from C, but I haven't found a way to do it from a script.

The earlier answers only work on Linux. For Mac OS X, I'm going to grep for VALGRIND_STARTUP_PWD in the environment in case someone doesn't have a better idea.

0


source to share


1 answer


from the shell:

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



This determines if the preloaded valgrind libraries are present in the process address map. This is reasonably efficient, but if you have a non-valgrind library that shares the nickname "/ valgrind" then you get false positive (unlikely).

[I changed the grep template from vg_preload to / valgrind as testing on Debian / Ubuntu showed that the library name was different, while a match in the valgrind directory will most likely succeed.]

+3


source







All Articles