终止在valgrind中运行的进程

时间:2011-09-06 14:17:16

标签: valgrind

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

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

1 个答案:

答案 0 :(得分:29)

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

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

因此,例如,如果我们在睡眠命令上启动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== 

然后杀死该命令:

bericote [~] % kill -TERM 9774

然后进程将退出并且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

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