ProcDump v1.1.1 - Sysinternals process dump utility Copyright (C) 2020 Microsoft Corporation. All rights reserved. Licensed under the MIT license. Mark Russinovich, Mario Hewardt, John Salem, Javid Habibi Monitors a process and writes a dump file when the process exceeds the specified criteria.
Process: progxyz (350498) CPU Threshold: n/a Commit Threshold: n/a Polling interval (ms): 1000 Threshold (s): 10 Number of Dumps: 1
Press Ctrl-C to end monitoring without terminating the process.
$ ls -l progxyz_time_2020-06-24_03\:30\:00.350498 -rw-r--r--. 1 root root 356848 Jun 24 03:30 progxyz_time_2020-06-24_03:30:00.350498 $ $ file progxyz_time_2020-06-24_03\:30\:00.350498 progxyz_time_2020-06-24_03:30:00.350498: ELF 64-bit LSB core file, x86-64, version 1 (SYSV), SVR4-style, from './progxyz', real uid: 0, effective uid: 0, real gid: 0, effective gid: 0, execfn: './progxyz', platform: 'x86_64' $
用 GNU 项目调试器分析核心文件。
要查看是否可以读取该转储文件,调用 GNU 项目调试器(gdb)。记得提供测试二进制文件的路径,这样你就可以看到堆栈上所有的函数名。在这里,bt(回溯)表明,当转储被采集时,sleep() 函数正在执行:
1 2 3 4 5 6 7 8 9 10 11 12
$ gdb -q ./progxyz ./progxyz_time_2020-06-24_03\:30\:00.350498 Reading symbols from ./progxyz...(no debugging symbols found)...done. [New LWP 350498] Core was generated by `./progxyz'. #0 0x00007fb6947e9208 in nanosleep () from /lib64/libc.so.6 Missing separate debuginfos, use: yum debuginfo-install glibc-2.28-101.el8.x86_64 (gdb) bt #0 0x00007fb6947e9208 in nanosleep () from /lib64/libc.so.6 #1 0x00007fb6947e913e in sleep () from /lib64/libc.so.6 #2 0x00000000004005f3 in main () (gdb)
gcore 怎么样?
Linux 用户会很快指出,Linux 已经有一个叫 gcore 的命令,大多数 Linux 发行版都有这个命令,它的作用和 ProcDump 完全一样。你说的对。如果你从来没有使用过它,可以尝试用 gcore 来转储一个进程的核心。再次运行测试程序,然后运行 gcore,并提供 PID 作为参数:
ProcDump v1.1.1 - Sysinternals process dump utility Copyright (C) 2020 Microsoft Corporation. All rights reserved. Licensed under the MIT license. Mark Russinovich, Mario Hewardt, John Salem, Javid Habibi Monitors a process and writes a dump file when the process exceeds the specified criteria.
Process: progxyz (pending) CPU Threshold: n/a Commit Threshold: n/a Polling interval (ms): 1000 Threshold (s): 10 Number of Dumps: 1
Press Ctrl-C to end monitoring without terminating the process.
[03:39:23 - INFO]: Waiting for process 'progxyz' to launch...
然后,从另一个终端调用测试二进制 progxyz:
1 2 3 4
$ ./progxyz & [1] 350951 $
ProcDump 立即检测到该二进制正在运行,并转储这个二进制的核心文件:
1 2 3 4 5 6 7 8 9 10 11 12 13
[03:39:23 - INFO]: Waiting for process 'progxyz' to launch... [03:43:22 - INFO]: Found process with PID 350951 [03:43:22 - INFO]: Timed: [03:43:23 - INFO]: Core dump 0 generated: progxyz_time_2020-06-24_03:43:22.350951 $
$ ls -l progxyz_time_2020-06-24_03\:43\:22.350951 -rw-r--r--. 1 root root 356848 Jun 24 03:43 progxyz_time_2020-06-24_03:43:22.350951 $ $ file progxyz_time_2020-06-24_03\:43\:22.350951 progxyz_time_2020-06-24_03:43:22.350951: ELF 64-bit LSB core file, x86-64, version 1 (SYSV), SVR4-style, from './progxyz', real uid: 0, effective uid: 0, real gid: 0, effective gid: 0, execfn: './progxyz', platform: 'x86_64' $
ProcDump v1.1.1 - Sysinternals process dump utility Copyright (C) 2020 Microsoft Corporation. All rights reserved. Licensed under the MIT license. Mark Russinovich, Mario Hewardt, John Salem, Javid Habibi Monitors a process and writes a dump file when the process exceeds the specified criteria.
Process: progxyz (351014) CPU Threshold: n/a Commit Threshold: n/a Polling interval (ms): 1000 Threshold (s): 10 Number of Dumps: 3
Press Ctrl-C to end monitoring without terminating the process.