HowTo: Debug Crashed Linux Application Core Files Like A Pro

2023-05-16

Core dumps are often used to diagnose or debug errors in Linux or UNIX programs. Core dumps can serve as useful debugging aids for sys admins to find out why Application like Lighttpd, Apache, PHP-CGI or any other program crashed. Many vendors and open source project author requests a core file to troubleshoot a program. A core file is generated when an application program abnormally terminates due to bug, operating system security protection schema, or program simply try to write beyond the area of memory it has allocated, and so on. This article explains how to turn on core file support and track down bugs in programs.

Turn On Core File Creation Support


By default most Linux distributions turn off core file creation (at least this is true for RHEL, CentOS, Fedora and Suse Linux). You need to use the ulimit command to configure core files.


See The Current Core File Limits


Type the following command:
# ulimit -c

Sample outputs:
0

The output 0 (zero) means core file is not created.


Change Core File Limits


In this example, set the size limit of core files to 75000 bytes:
# ulimit -c 75000

HowTo: Enable Core File Dumps For Application Crashes And Segmentation Faults


Edit /etc/profile file and find line that read as follows to make persistent configuration:
ulimit -S -c 0 > /dev/null 2>&1

Update it as follows:
ulimit -c unlimited >/dev/null 2>&1

Save and close the file. Edit /etc/sysctl.conf, enter:
# vi /etc/sysctl.conf

Append the following lines:

kernel.core_uses_pid = 1
kernel.core_pattern = /tmp/core-%e-%s-%u-%g-%p-%t
fs.suid_dumpable = 2

Save and close the file. Where,

  1. kernel.core_uses_pid = 1 – Appends the coring processes PID to the core file name.
  2. fs.suid_dumpable = 2 – Make sure you get core dumps for setuid programs.
  3. kernel.core_pattern = /tmp/core-%e-%s-%u-%g-%p-%t – When the application terminates abnormally, a core file should appear in the /tmp. The kernel.core_pattern sysctl controls exact location of core file. You can define the core file name with the following template whih can contain % specifiers which are substituted by the following values when a core file is created:
  • %% – A single % character
  • %p – PID of dumped process
  • %u – real UID of dumped process
  • %g – real GID of dumped process
  • %s – number of signal causing dump
  • %t – time of dump (seconds since 0:00h, 1 Jan 1970)
  • %h – hostname (same as ’nodename’ returned by uname(2))
  • %e – executable filename

Finally, enable debugging for all apps, enter (Redhat and friends specific):
# echo "DAEMON_COREFILE_LIMIT='unlimited'" >> /etc/sysconfig/init

Reload the settings in /etc/sysctl.conf by running the following command:
# sysctl -p

How Do I Enable Core Dumping For Specific Deamon?


To enable core dumping for specific deamons, add the following line in the /etc/sysconfig/daemon-file file. In this example, edit /etc/init.d/lighttped and add line as follows:
DAEMON_COREFILE_LIMIT='unlimited'

Please note that DAEMON_COREFILE_LIMIT is Redhat specific, for all other distro add configuration as follows:
ulimit -c unlimited >/dev/null 2>&1
echo /tmp/core-%e-%s-%u-%g-%p-%t > /proc/sys/kernel/core_pattern

Save and close the file. Restart / reload lighttpd:
# /etc/init.d/lighttpd restart
# su - lighttpd
$ ulimit -c

Sample outputs:
unlimited

Now, you can send core files to vendor or software writes.


How Do I Read Core Files?

gdb command


You need use the gdb command as follows:
$ gdb /path/to/application /path/to/corefile

Refer to gdb man page for more information:
$ man gdb



strace command


System administrators, diagnosticians and trouble-shooters will find it invaluable for solving problems with programs for which the source is not readily available since they do not need to be recompiled in order to trace them. This is also useful to submit bug reports to open source developers. See how to use the strace command under Linux to debug the problems.

strace is a useful diagnostic, instructional, and debugging tool. It can save lots of headache. System administrators, diagnosticians and trouble-shooters will find it invaluable for solving problems with programs for which the source is not readily available since they do not need to be recompiled in order to trace them. This is also useful to submit bug reports to open source developers.

Each line in the trace contains the system call name, followed by its arguments in parentheses and its return value.

Run strace against /bin/foo and capture its output to a text file in output.txt:
$ strace -o output.txt /bin/foo

You can strace the webserver process and see what it’s doing. For example, strace php5 fastcgi process, enter:
$ strace -p 22254 -s 80 -o /tmp/debug.lighttpd.txt

To see only a trace of the open, read system calls, enter :
$ strace -e trace=open,read -p 22254 -s 80 -o debug.webserver.txt

Where,

  • -o filename : Write the trace output to the file filename rather than to screen (stderr).
  • -p PID : Attach to the process with the process ID pid and begin tracing. The trace may be terminated at any time by a keyboard interrupt signal (hit CTRL-C). strace will respond by detaching itself from the traced process(es) leaving it (them) to continue running. Multiple -p options can be used to attach to up to 32 processes in addition to command (which is optional if at least one -p option is given).
  • -s SIZE : Specify the maximum string size to print (the default is 32).

Refer to strace man page for more information:
$ man strace


From:

【1】HowTo: Debug Crashed Linux Application Core Files Like A Pro
【2】Debugging Tip: Trace the Process and See What It is Doing with strace


本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

HowTo: Debug Crashed Linux Application Core Files Like A Pro 的相关文章

  • Locale.getDefault() 始终返回 en

    unix 机器上的服务器始终使用 en 作为默认区域设置 以下是区域设置输出 LANG en US LC CTYPE C LC NUMERIC C LC TIME C LC COLLATE C LC MONETARY C LC MESSAG
  • 在 Mac OS X 上构建 Linux 内核

    我正在做一个修改Linux内核的项目 我有一台桌面 Linux 机器 在上面构建内核没有问题 不过 我要去旅行 我想在途中工作 我只有一台 MacBook 当我尝试构建 Linux 内核时 它抱怨说elf h was not found 我
  • Unix 命令列出包含字符串但*不*包含另一个字符串的文件

    如何递归查看包含一个字符串且不包含另一个字符串的文件列表 另外 我的意思是评估文件的文本 而不是文件名 结论 根据评论 我最终使用了 find name html exec grep lR base maps xargs grep L ba
  • 修改linux下的路径

    虽然我认为我已经接近 Linux 专业人士 但显然我仍然是一个初学者 当我登录服务器时 我需要使用最新版本的R 统计软件 R 安装在 2 个地方 当我运行以下命令时 which R I get usr bin R 进而 R version
  • bluetoothctl 到 hcitool 等效命令

    在 Linux 中 我曾经使用 hidd connect mmac 来连接 BT 设备 但自 Bluez5 以来 这种情况已经消失了 我可以使用 bluetoothctl 手动建立连接 但我需要从我的应用程序使用这些命令 并且使用 blue
  • 为什么我收到“无法进行二进制日志记录”的信息。在我的 MySQL 服务器上?

    当我今天启动 MySQL 服务器并尝试使用以下命令进行一些更改时用于 MySQL 的 Toad http www quest com toad for mysql 我收到此消息 MySQL 数据库错误 无法进行二进制日志记录 消息 交易级别
  • 如何禁用 GNOME 桌面屏幕锁定? [关闭]

    Closed 这个问题不符合堆栈溢出指南 help closed questions 目前不接受答案 如何阻止 GNOME 桌面在几分钟空闲时间后锁定屏幕 我已经尝试过官方手册了在红帽 https access redhat com doc
  • 如何根据 HTTP 请求使用 Python 和 Flask 执行 shell 命令并流输出?

    下列的这个帖子 https stackoverflow com questions 15092961 how to continuously display python output in a webpage 我能够tail f网页的日志
  • chown:不允许操作

    我有问题 我需要通过 php 脚本为系统中的不同用户设置文件所有者权限 所以我通过以下命令执行此操作 其中 1002 是系统的用户 ID file put contents filename content system chown 100
  • sendfile64 只复制约2GB

    我需要使用 sendfile64 复制大约 16GB 的文件 到目前为止我所取得的成就是 include
  • fopen 不返回

    我在 C 程序中使用 fopen 以只读模式 r 打开文件 但就我而言 我观察到 fopen 调用没有返回 它不返回 NULL 或有效指针 执行在 fopen 调用时被阻止 文件补丁绝对正确 我已经验证过 并且不存在与权限相关的问题 任何人
  • 域套接字“sendto”遇到“errno 111,连接被拒绝”

    我正在使用域套接字从另一个进程获取值 就像 A 从 B 获取值一样 它可以运行几个月 但最近 A 向 B 发送消息时偶尔会失败 出现 errno 111 连接被拒绝 我检查了B域套接字绑定文件 它是存在的 我也在另一台机器上做了一些测试 效
  • arm64和armhf有什么区别?

    Raspberry Pi Type 3 具有 64 位 CPU 但其架构不是arm64 but armhf 有什么区别arm64 and armhf armhf代表 arm hard float 是给定的名称Debian 端口 https
  • 尝试安装 LESS 时出现“请尝试以 root/管理员身份再次运行此命令”错误

    我正在尝试在我的计算机上安装 LESS 并且已经安装了节点 但是 当我输入 node install g less 时 出现以下错误 并且不知道该怎么办 FPaulMAC bin paul npm install g less npm ER
  • 如何在Linux内核源代码中打印IP地址或MAC地址

    我必须通过修改 Linux 内核源代码来稍微改变 TCP 拥塞控制算法 但为了检查结果是否正确 我需要记录 MAC 或 IP 地址信息 我使用 PRINTK 函数来打印内核消息 但我感觉很难打印出主机的MAC IP地址 printk pM
  • 将 PDF 转换为 600dpi 的 TIFF 和 jpg 96 dpi

    我想使用 ImageMagick 从 Python 脚本将 pdf 转换为 600 dpi 的 tiff 和 96 dpi 的 jpg 我使用 imagemagick 命令行完成了这项任务 但我想使用python中的Imagemagick将
  • os.Mkdir 和 os.MkdirAll 权限

    我正在尝试在程序开始时创建一个日志文件 我需要检查是否 log如果不创建目录 则目录存在 然后继续创建日志文件 好吧 我尝试使用os Mkdir 也os MkdirAll 但无论我在第二个参数中输入什么值 我都会得到一个没有权限的锁定文件夹
  • Linux:如何从特定端口发送TCP数据包?

    如何打开原始套接字以从特定 TCP 端口发送 我希望所有连接始终来自临时端口以下的一系列端口 如果您正在使用raw套接字 然后只需在数据包标头中填写正确的 TCP 源端口即可 相反 如果您使用 TCP 套接字接口 socket connec
  • 安装J语言的JQt IDE,出现错误

    我一直按照这里的说明进行操作 http code jsoftware com wiki System Installation Linux http code jsoftware com wiki System Installation L
  • iptables通过注释删除特定规则

    我需要删除一些具有相同评论的规则 例如 我有带有 comment test it 的规则 所以我可以像这样获得它们的列表 sudo iptables t nat L grep test it 但是我怎样才能删除所有带有注释 测试它 的 PR

随机推荐

  • Linux下C语言实现文件遍历,支持嵌套和文件数量统计

    Linux命令行下有两个非常基本的命令 xff0c 一个是ls xff0c 一个是tree xff0c 其分别能够列出当前目录下的文件和树形方式嵌套显示目录结构 因为网络上有很多版本的文件遍历代码 xff0c 代码都没有整理过 xff0c
  • Linux系统参数配置简介

    Linux服务器在对应用程序进行优化配置的时候 xff0c 经常使用到sysctl和PAM两个模块对服务器进行优化 关于这两块的介绍也很多 xff0c 这里主要集中了相关内容 xff0c 并整体做了一个介绍 sysctl内核参数配置 使用
  • WindowsXp重启后,如何取消图标自动重排?

    问题现象 xff1a 在桌面右键 gt 排列图标 gt 自动排列 xff0c 功能取消后 xff08 对号去掉 xff09 xff0c 把图标拉到了桌面的右侧 可是注销或重启电脑之后 xff0c 图标又变成自动排列了 自动排列的对号也又自动
  • WindowsXp重启后,自定义任务栏丢失

    大致有以下几个原因导致自定义任务栏丢失 xff1a 第一 xff0c 系统设置 xff0c 重启时默认移除所有自定义任务栏 第二 xff0c 优化软件将自定义任务栏优化了 大致可以采用以下方法解决任务栏问题 xff1a 1 快速启动栏丢失
  • Linux应用程序之Helloworld入门

    对于初学者来说 xff08 本人就是 xff09 xff0c 如何开始写第一个程序至关重要 有的时候一个简单的问题会严重影响到学习的积极性和自信心 这里结合实际工作中的一些经验 xff0c 总结方法步骤 xff0c 对Linux下应用程序H
  • TCP Socket链接检测方法

    TCP网络应用程序开发中 xff0c 如果遇到了需要检查Socket链接问题 xff0c 通常是对这个TCP通道的时效性提出了要求 应用开发诉求 1 xff09 客户端需要了解管道提供正常数据通信链路 2 xff09 客户端需要确保管道异常
  • 一座逝去的里程碑VxWorks2Linux

    曾今有幸从事过VxWorks到Linux系统的应用层代码移植 xff0c 也没有总结过 只有涉及大量存量代码的公司才会存在该问题 xff0c 而实际情况证明 xff0c 即使有百万行代码的公司 xff0c 也会借助这种契机剥离API的依赖
  • 一个问题阻止Windows正确检查此机器的许可证

    遇到windows SP3更新问题 更新后 xff0c 系统启动弹出对话框提示 一个问题阻止Windows正确检查此机器的许可证 错误代码 xff1a 0x80070002 我的电脑问题解决方法 xff1a 从另外一台PC上复制了以下两个文
  • Linux下bash配置及执行顺序

    用户bash配置 1 bash history xff1a 记录了用户以前输入的命令 xff0c 2 bash login xff1a 如果 bash profile找不到 xff0c 则bash尝试读取这个脚本 3 bash logout
  • 在WindowsXp上如何设置默认其他浏览器

    设置默认浏览器 xff0c 相信大部分时间大家是默认打开IE或者其他浏览器的时候根据提示框设置的 以前我也从来不关注这个 xff0c 能用 xff0c 能上网看东西就可以了 但是越来越多的时间不使用IE了 xff0c 感觉有些工具或者Goo
  • Libsvm使用笔记【matlab】

    根据以下教程配置 xff1a 1038条消息 LIBSVM 繁拾简忆的博客 CSDN博客 https blog csdn net u014772862 category 6280683 html 目录 xff1a 一 libsvm使用 二
  • putty登录默认安装ubuntu,中文显示乱码问题

    putty是windows上常用的登录linux的终端工具 默认情况下安装的ubuntu xff0c 终端上显示的中文字符常常是乱码 这里给出一个简单的方法进行配置 确保ls命令能正常显示中文字符 第一步 xff1a 双击putty exe
  • C语言中#宏的一些用法和预编译宏展开问题

    宏定义大家都用过 xff0c 但是有些技巧性的宏应用 xff0c 在版本管理等方面有很重要的应用 这里我们介绍下 宏的一些用法 xff1a define Conn x y x y define ToChar x 64 x define To
  • 直接登录Windows桌面,不显示欢迎/登录屏幕

    Windows XP是一个比较安全的操作系统 xff0c 每次启动时都要求选择账户并输入密码 xff0c 对于公用电脑 xff0c 这样当然更安全 xff0c 但是如果这台电脑是一个人用 xff0c 每次都要选择帐户并输入密码实在太麻烦了
  • linux与linux,linux与windows,windows与linux之间SSH文件传输

    linux与linux之间传送文件 xff1a scp filename username 64 ip filename 例 xff1a gt scp appc daniel 64 10 141 44 203 home daniel Pas
  • 评:C语言18个经典问题答录

    C语言18个经典问题答录这个大家都看过 xff0c 自己也仔细看了一遍 xff0c 另外 xff0c 将一点感悟加注了一下 1 这样的初始化有什么问题 xff1f char p 61 malloc 10 编译器提示 非法初始式 云云 答 这
  • Windows & Linux 关机命令

    Windows命令关机 gt shutdown s t 0 gt shutdown h 用法 shutdown i l s r a f m computername t xx c 34 comment 34 d up xx yy 没有参数
  • Linux动态库(.so)搜索路径(目录)设置方法

    众所周知 xff0c Linux动态库的默认搜索路径是 lib和 usr lib 动态库被创建后 xff0c 一般都复制到这两个目录中 当程序执行时需要某动态库 xff0c 并且该动 态库还未加载到内存中 xff0c 则系统会自动到这两个默
  • gdb重定向stdout和stderr输出到调试窗口

    步骤一 xff1a 查找需要attach的进程 ps aux grep prm 步骤二 xff1a 使用gdb attach到进程 gdb attach 8930 步骤三 xff1a 重新定向输出日志 gdb call close 1 1
  • HowTo: Debug Crashed Linux Application Core Files Like A Pro

    Core dumps are often used to diagnose or debug errors in Linux or UNIX programs Core dumps can serve as useful debugging