c – 每个进程可配置的核心转储目录

前端之家收集整理的这篇文章主要介绍了c – 每个进程可配置的核心转储目录前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
有没有办法配置为特定进程放置核心转储文件的目录?

我有一个用C编写的守护进程,我想为其配置核心转储目录.可选地,文件名模式也应该是可配置的.

我知道/ proc / sys / kernel / core_pattern,但这会全局改变模式和目录结构.

Apache有指令CoreDumpDirectory – 所以它似乎是可能的.

解决方法

不,您无法按流程设置它.如果模式包含目录,则核心文件将转储到进程的当前工作目录或/ proc / sys / kernel / core_pattern中设置的目录.

apache中的CoreDumpDirectory是一个hack,apache为所有导致核心转储的信号注册信号处理程序,并更改其信号处理程序中的当前目录.

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

猜你在找的C&C++相关文章