【问题标题】:Terminate process running inside valgrind终止在 valgrind 中运行的进程
【发布时间】:2011-09-06 14:17:16
【问题描述】:

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

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

【问题讨论】:

    标签: valgrind


    【解决方案1】:

    没有“内部进程”,因为 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== 
    

    然后终止该命令:

    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 没有机会做任何事情。

    【讨论】:

    • 我在询问之前尝试了kill -SIGTERM,但是 valgrind 需要很长时间才能停止(约 10 分钟),所以我怀疑它不起作用。感谢您的回答。
    • 延迟是它扫描所有分配的内存,试图找出是否有任何泄漏 - 这可能需要比正常情况更长的时间,因为正在运行的程序可能分配的内存比一个正常退出的。
    • 在 OS X 10.7.5 和 valgrind-3.8.1 上不是这样。 valgrind 会很高兴地忽略杀戮。
    • 这似乎不适用于我在 ubuntu 14 和 valgrind 3.8 上。该进程在没有正确日志的情况下终止
    • Centos: kill -SIGTERM (或 SIGUSR1, SIGUSR2) 用摘要停止了 valgrind。
    猜你喜欢
    • 1970-01-01
    • 2021-07-26
    • 1970-01-01
    • 2018-02-14
    • 2023-03-11
    • 2012-08-20
    • 1970-01-01
    • 2013-05-27
    • 1970-01-01
    相关资源
    最近更新 更多