linux: 有没有办法找出哪个进程生成了核心文件?

linux: is there a way to find out which process generated a core file?

我的系统生成了一些核心文件,但是这些核心文件的后缀只有时间戳,没有进程id信息。

那么在核心文件中是否有任何与进程 ID 相关的信息,以便我可以从 gdb 或其他工具中知道它?

是的,使用"file"命令。

file <core_file>

这应该告诉您 executable/command 导致核心转储的原因。如果这不是您所需要的,请告诉我。

So it there any process id related information inside core files

肯定会。

core文件中,有一组ELF笔记。您正在寻找的笔记是 NT_PRPSINFO 类型,它包含(除其他外)您想要的 pr_pid

typedef struct prpsinfo {       /* Information about process                 */
  unsigned char  pr_state;      /* Numeric process state                     */
  char           pr_sname;      /* Char for pr_state                         */
  unsigned char  pr_zomb;       /* Zombie                                    */
  signed char    pr_nice;       /* Nice val                                  */
  unsigned long  pr_flag;       /* Flags                                     */
  uint32_t       pr_uid;        /* User ID                                   */
  uint32_t       pr_gid;        /* Group ID                                  */

  pid_t          pr_pid;        /* Process ID                                */
  pid_t          pr_ppid;       /* Parent's process ID                       */
  pid_t          pr_pgrp;       /* Group ID                                  */
  pid_t          pr_sid;        /* Session ID                                */
  char           pr_fname[16];  /* Filename of executable                    */
  char           pr_psargs[80]; /* Initial part of arg list                  */

} prpsinfo;

问题是:哪些工具可以找到并解码这张纸条。从 elfutils.

尝试 eu-readelf