Terminate process running inside valgrind

后端 未结 1 658
终归单人心
终归单人心 2021-02-03 20:58

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条回答
  • 2021-02-03 21:17

    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.

    0 讨论(0)
提交回复
热议问题