linux系统打开core文件设置

[| 不指定 2011/10/14 23:30]
| |
  默认linux系统是不开启core文件的,不过对于运行较多自己写的程序的服务器,开启core文件还是很有必要的。

  首先设置ulimit允许core文件,默认0,不允许。
  使用ulimit -c可以设置,但不是永久的。通过编辑/etc/security/limits.conf 文件可以永久改变这一设置。

  加入两行:
*               soft    core            unlimited
root           soft    core            unlimited

  要对root单独设置,刚开始只设置了*,后来发现没有对root生效。

  默认core文件路径和core文件名都不太好,放到固定位置,使用固定规则生成core文件是比较好的选择。

  /proc/sys/kernel/core_uses_pid可以控制产生的core文件的文件名中是否添加pid作为扩展,如果添加则文件内容为1,否则为0
  echo 1 > /proc/sys/kernel/core_uses_pid

  /proc/sys/kernel/core_pattern可以设置格式化的core文件保存位置或文件名,默认文件内容是core
  可以这样修改:
  echo "/corefile/core-%e-%p-%t" > core_pattern
  将会控制所产生的core文件会存放到/corefile目录下,产生的文件名为core-命令名-pid-时间戳
  以下是参数列表:
    %p - insert pid into filename 添加pid
    %u - insert current uid into filename 添加当前uid
    %g - insert current gid into filename 添加当前gid
    %s - insert signal that caused the coredump into the filename 添加导致产生core的信号
    %t - insert UNIX time that the coredump occurred into filename 添加core文件生成时的unix时间
    %h - insert hostname where the coredump happened into filename 添加主机名
    %e - insert coredumping executable name into filename 添加命令名
by snooda | 分类: 默认分类 | 评论(0) | 引用(0) | 阅读(5497)
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]