终止在valgrind中运行的进程

Ant*_*rez 30 valgrind

杀死valgrind进程本身不会留下内部进程执行的报告.

是否可以向valgrind内部运行的进程发送终止信号?

Tom*_*omH 29

没有"内部进程",因为valgrind本身和它运行的客户端程序都在一个进程中执行.

发送到该进程的信号将照常传送到客户端程序.如果信号导致进程终止,那么valgrind的正常退出处理程序将运行并(例如)报告任何泄漏.

所以,例如,如果我们在sleep命令上启动valgrind:

bericote [~] % valgrind sleep 240
==9774== Memcheck, a memory error detector
==9774== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
==9774== Using Valgrind-3.6.1 and LibVEX; rerun with -h for copyright info
==9774== Command: sleep 240
==9774== 
Run Code Online (Sandbox Code Playgroud)

然后杀掉那个命令:

bericote [~] % kill -TERM 9774
Run Code Online (Sandbox Code Playgroud)

然后进程将退出并且valgrind的退出处理程序将运行:

==9774== 
==9774== HEAP SUMMARY:
==9774==     in use at exit: 0 bytes in 0 blocks
==9774==   total heap usage: 30 allocs, 30 frees, 3,667 bytes allocated
==9774== 
==9774== All heap blocks were freed -- no leaks are possible
==9774== 
==9774== For counts of detected and suppressed errors, rerun with: -v
==9774== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 6 from 6)
[1]    9774 terminated  valgrind sleep 240
Run Code Online (Sandbox Code Playgroud)

唯一的例外是kill -9因为在这种情况下,进程被内核杀死而没有被告知信号,因此valgrind没有机会做任何事情.

  • 在OS X 10.7.5和valgrind-3.8.1上不是这样.valgrind会高兴地忽略杀戮. (8认同)
  • 在OSX上`kill -SIGBUS`工作正常 (3认同)