在 Debian 9 上启用核心转储

Enabling core dumps on Debian 9

我注意到我的 Debian 9 VM 没有使用 kill -s 6 <pid> 创建核心转储。查看了 ulimit、suid_dumpable、core_pattern - 它们对我来说似乎没问题。 kill 后的消息不显示 (core dumped),工作目录或 core_pattern。须藤没有帮助。我缺少任何配置吗?

配置:

   Static hostname: <hostname>
         Icon name: computer-vm
           Chassis: vm
        Machine ID: <redacted>
           Boot ID: <redacted>
    Virtualization: microsoft
  Operating System: Debian GNU/Linux 9 (stretch)
            Kernel: Linux 4.19.128-dcc08d126b2b
      Architecture: x86-64
<user>@<hostname>:~$ ulimit -Ha
core file size          (blocks, -c) unlimited
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 56048
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1048576
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) unlimited
cpu time               (seconds, -t) unlimited
max user processes              (-u) 56048
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited
<user>@<hostname>:~$ ulimit -Sa
core file size          (blocks, -c) 100000
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 56048
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 56048
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited
<user>@<hostname>:~$ cat /proc/sys/fs/suid_dumpable
1
<user>@<hostname>:~$ cat /proc/sys/kernel/core_pattern
/opt/core/%e.SIG-%s.%p.core

示例:

<user>@<hostname>:~$ sleep 500 &
[1] 14259
<user>@<hostname>:~$ kill -s 6 14259
[1]+  Aborted                 sleep 500
<user>@<hostname>:~$ ls -la /opt/core/
total 8
drwxr-xr-x 2 root root 4096 Jun  8 15:27 .
drwxr-xr-x 6 root root 4096 Jun  8 15:27 ..
<user>@<hostname>:~$ ls -la | grep core
<user>@<hostname>:~$

也许你的系统被systemd弄乱了。在这种情况下,您必须安装 systemd-coredump:

# apt-get install systemd-coredump 

接下来您可以使用 coredumpctl 检查核心转储。

# sleep 100
^\Quit (core dumped)
# coredumpctl list
TIME                            PID   UID   GID SIG COREFILE  EXE
Tue 2021-06-15 18:00:58 CEST  21065     0     0   3 present   /bin/sleep

它们被放置在 /var/lib/systemd/coredump.

# ll /var/lib/systemd/coredump/
total 68
-rw-r----- 1 root root 26605 Jun 15 18:00 core.sleep.0.af2fa0f571f84f279c4510ee3281a787.21065.1623772857000000.lz4