Terminate process running inside valgrind

ⅰ亾dé卋堺 提交于 2019-12-03 08:16:48

问题


Killing the valgrind process itself leaves no report on the inner process' execution.

Is it possible to send a terminate signal to a process running inside valgrind?


回答1:


There is no "inner process" as both valgrind itself and the client program it is running execute in a single process.

Signals sent to that process will be delivered to the client program as normal. If the signal causes the process to terinate then valgrind's normal exit handlers will run and (for example) report any leaks.

So, for example, if we start valgrind on a sleep command:

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== 

then kill that command:

bericote [~] % kill -TERM 9774

then the process will exit and valgrind's exit handlers will run:

==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

The only exception would be for kill -9 as in that case the process is killed by the kernel without ever being informed of the signal so valgrind has no opportunity to do anything.



来源:https://stackoverflow.com/questions/7321398/terminate-process-running-inside-valgrind

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!