2010-04-23 54 views
6

有沒有辦法配置核心轉儲文件放置在特定進程的目錄?每個進程可配置的核心轉儲目錄

我有一個用C++編寫的守護進程,我想配置核心轉儲目錄。可選的文件名模式也應該是可配置的。

我知道關於/proc/sys/kernel/core_pattern,但是這會改變模式和目錄結構全局

Apache的指令CoreDumpDirectory - 所以它似乎是可能的。

回答

14

不,您無法設置每個進程。核心文件被轉儲到進程的當前工作目錄,或者如果模式包含一個目錄,則轉儲到/ proc/sys/kernel/core_pattern中設置的目錄。

apache中的CoreDumpDirectory是一個黑客,Apache爲所有導致核心轉儲的信號註冊信號處理程序,並更改其信號處理程序中的當前目錄。

/* handle all varieties of core dumping signals */ 
static void sig_coredump(int sig) 
{ 
    apr_filepath_set(ap_coredump_dir, pconf); 
    apr_signal(sig, SIG_DFL); 
#if AP_ENABLE_EXCEPTION_HOOK 
    run_fatal_exception_hook(sig); 
#endif 
    /* linuxthreads issue calling getpid() here: 
    * This comparison won't match if the crashing thread is 
    * some module's thread that runs in the parent process. 
    * The fallout, which is limited to linuxthreads: 
    * The special log message won't be written when such a 
    * thread in the parent causes the parent to crash. 
    */ 
    if (getpid() == parent_pid) { 
     ap_log_error(APLOG_MARK, APLOG_NOTICE, 
        0, ap_server_conf, 
        "seg fault or similar nasty error detected " 
        "in the parent process"); 
     /* XXX we can probably add some rudimentary cleanup code here, 
     * like getting rid of the pid file. If any additional bad stuff 
     * happens, we are protected from recursive errors taking down the 
     * system since this function is no longer the signal handler GLA 
     */ 
    } 
    kill(getpid(), sig); 
    /* At this point we've got sig blocked, because we're still inside 
    * the signal handler. When we leave the signal handler it will 
    * be unblocked, and we'll take the signal... and coredump or whatever 
    * is appropriate for this particular Unix. In addition the parent 
    * will see the real signal we received -- whereas if we called 
    * abort() here, the parent would only see SIGABRT. 
    */ 
}