终止在 valgrind 中运行的进程 [英] Terminate process running inside valgrind

查看:57
本文介绍了终止在 valgrind 中运行的进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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

推荐答案

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

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

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

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.

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

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

然后终止该命令:

bericote [~] % kill -TERM 9774

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

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

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

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.

这篇关于终止在 valgrind 中运行的进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆