从进程内部转储 Linux 核心文件的好方法是什么? [英] What is a good way to dump a Linux core file from inside a process?

查看:10
本文介绍了从进程内部转储 Linux 核心文件的好方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个服务器(用 C 和 C++ 编写)当前捕获 SEGV 并将一些内部信息转储到文件中.我想在我们捕获 SEGV 时生成一个核心文件并将其写入磁盘,因此我们的支持代表和客户不必对 ulimit 大惊小怪,然后等待崩溃再次发生以获得核心文件.我们过去使用过 abort 函数,但它受制于 ulimit 规则,并没有帮助.

We have a server (written in C and C++) that currently catches a SEGV and dumps some internal info to a file. I would like to generate a core file and write it to disk at the time we catch the SEGV, so our support reps and customers don't have to fuss with ulimit and then wait for the crash to happen again in order to get a core file. We have used the abort function in the past, but it is subject to the ulimit rules and doesn't help.

我们有一些遗留代码可以读取/proc/pid/map 并手动生成核心文件,但它已经过时,而且看起来不太便携(例如,我猜它在我们的 64 位版本).在 Linux 进程中生成和转储核心文件的最佳方法是什么?

We have some legacy code that reads /proc/pid/map and manually generates a core file, but it is out of date, and doesn't seem very portable (for example, I'm guessing it would not work in our 64 bit builds). What is the best way to generate and dump a core file in a Linux process?

推荐答案

Google 有一个库,用于从正在运行的进程内部生成核心转储,名为 google-coredumper.这应该忽略 ulimit 和其他机制.

Google has a library for generating coredumps from inside a running process called google-coredumper. This should ignore ulimit and other mechanisms.

生成核心文件的调用文档位于此处.根据文档,在信号处理程序中生成核心文件似乎是可行的,但不能保证始终有效.

The documentation for the call that generates the core file is here. According to the documentation, it seems that it is feasible to generate a core file in a signal handler, though it is not guaranteed to always work.

这篇关于从进程内部转储 Linux 核心文件的好方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆