views:

209

answers:

2

Hi, How can I send a signal to my process which runs inside valgrind to check its memory usage status?

Thanks!

+1  A: 

There is not a signal that tells valgrind to check its memory usage status. If you are interested in the amount of memory used by your program over time and where that memory is allocated, valgrind's massif tool can record that information, which can then be displayed using its ms_print utility. Massif records snapshots of the program's memory usage automatically throughout the execution of the program, including a peak snapshot representing the point at which the memory usage was at its peak (within 1% using the default options).

To run your program under valgrind's massif tool:

valgrind --tool=massif yourprogram

A binary file massif.out.pid will be created. Use ms_print to format the information in text form:

ms_print massif.out.12345
mark4o
Ah, thank you. My program need to accept a signal number 40 to exit. It is a server daemon, so the only way I make it exit is to send a signal 40, and the sig handler will make the program exit. So, when I check its memory usage in valgrind, I can't find a way to send a signal to it, because, there is no process of that program at all. Is there anyway I can send a signal to my program? Thanks!
Yang Bo
If you send the signal to the valgrind process that is running your program then valgrind will pass it on to your program's signal handler.
mark4o
A: 

To send a signal to valgrind, pkill -USR1 valgrind doesn't want to work for me.

pkill -USR1 memcheck

do the trick.

Laurent Debricon