linux – 在殺死程序之前儲存gmon.out
我想使用gprof配置一個守護程序.我的守護程序使用第三方庫,它註冊一些回撥,然後呼叫一個主函式,從不返回.我需要呼叫kill(SIGTERM或SIGKILL)來終止守護程序.不幸的是,gprof的手冊頁面顯示如下:
The profiled program must call “exit”(2) or return normally for theprofiling information to be saved in the gmon.out file.
有沒有辦法儲存針對使用SIGTERM或SIGKILL殺死的程序的分析資訊?
#include <dlfcn.h> #include <stdio.h> #include <unistd.h> void sigUsr1Handler(int sig) { fprintf(stderr, "Exiting on SIGUSR1\n"); void (*_mcleanup)(void); _mcleanup = (void (*)(void))dlsym(RTLD_DEFAULT, "_mcleanup"); if (_mcleanup == NULL) fprintf(stderr, "Unable to find gprof exit hook\n"); else _mcleanup(); _exit(0); } int main(int argc, char* argv[]) { signal(SIGUSR1, sigUsr1Handler); neverReturningLibraryFunction(); }
http://stackoverflow.com/questions/10205543/saving-gmon-out-before-killing-a-process