设置 core dump文件名的格式

可以在/etc/sysctl.conf里设置。

 cat sysctl.conf 
kernel.core_pattern =%e.core.%p
kernel.core_uses_pid = 0

%e: 可执行文件名

%p: 进程的PID

%u: real uid of the process

%g: real gid of the process

%t: the time when the core is dumped

%h: host name

%c: the max size of the core dump file

在上面的设置下,如果一个名为 test的程序产生了core dump, 则他的名字为 test.core.123 (这里假设其pid为  123)

如果在 sysctl.conf里改变了设置,之后要执行 sysctl -p 使之生效。


设置生成压缩的 core文件

首先,创建文件 core_helper:

#cat usr/sbin/core_helper 
#!/bin/sh
exec gzip - > /root/$1.core.$2.gz
修改 sysctl.conf文件内容:

#cat etc/sysctl.conf 
kernel.core_pattern = |/usr/sbin/core_helper %e %p 
kernel.core_uses_pid = 0

#cat /proc/sys/kernel/core_pattern 
|/usr/sbin/core_helper %e %p

重新执行  sysctl -p 之后,就会生成  test.core.1234.gz 这样的文件。

man core 里有对于这个管道符号的解释:

      Since  kernel  2.6.19,  Linux  supports  an  alternate  syntax  for the
       /proc/sys/kernel/core_pattern file.  If the  first  character  of  this
       file  is  a  pipe  symbol (|), then the remainder of the line is inter‐
       preted as a program to be executed.  Instead of being written to a disk
       file,  the  core  dump is given as standard input to the program.  Note
       the following points:

       *  The program must be specified using an absolute pathname (or a path‐
          name relative to the root directory, /), and must immediately follow
          the '|' character.

       *  The process created to run the program runs as user and group root.

       *  Command-line arguments can be supplied to the program (since  kernel
          2.6.24),  delimited by white space (up to a total line length of 128
          bytes).

       *  The command-line arguments can  include  any  of  the  %  specifiers
          listed  above.   For example, to pass the PID of the process that is
          being dumped, specify %p in an argument.


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值