有没有办法配置为特定进程放置核心转储文件的目录?
我有一个用C编写的守护进程,我想为其配置核心转储目录.可选地,文件名模式也应该是可配置的.
我知道/ proc / sys / kernel / core_pattern,但这会全局改变模式和目录结构.
Apache有指令CoreDumpDirectory – 所以它似乎是可能的.
解决方法
不,您无法按流程设置它.如果模式包含目录,则核心文件将转储到进程的当前工作目录或/ proc / sys / kernel / core_pattern中设置的目录.
apache中的CoreDumpDirectory是一个hack,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,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. */ }