一、ulimit命令设置core文件最大size
ulimit:Modify shell resource limits.(只对当前shell有效)
-S soft 当前用户限制。
-H hard 当前用户限制上限。
-a all current limits are reported.
规则1:值以1024-byte为单位,如core file size。
规则2:hard限制必须大于soft限制
规则3:不带S和H参数时,默认设置soft值;但如果hard值为unlimited,也会更改hard值。
print_limit() {
ulimit -c
ulimit -Sc
ulimit -Hc
}
ulimit -Hc unlimited
print_limit
ulimit -c 1000
print_limit
ulimit -Sc 500
print_limit
ulimit -Hc 2000
print_limit
二、core文件位置设置查看(core pattern)
变量替换规则:
%% a single % character
%p PID of dumped process
%u (numeric) real UID of dumped process
%g (numeric) real GID of dumped process
%s number of signal causing dump
%t time of dump, expressed as seconds since the Epoch
%h hostname (same as nodename returned by uname(2))
%e executable filename (without path prefix)
%c core file size soft resource limit of crashing process
查看core文件位置:cat /proc/sys/kernel/core_pattern
修改core文件位置:echo "core-%e-%p-%t" > /proc/sys/kernel/core_pattern,重启后系统会恢复默认。
查看是否使用pid:cat /proc/sys/kernel/core_uses_pid
修改是否使用pid:echo 1 > /proc/sys/kernel/core_uses_pid,当core pattern里面不包含pid时,系统自动添加.pid。
三、sysctl命令
1 linux系统启动时从/etc/sysctl.conf文件加载系统运行时配置。
2 从配置文件重新加载系统运行时配置:sysctl -p /etc/sysctl.conf。
sysctl - configure kernel parameters at runtime.(配置项在/proc/sys/目录下,重启后系统会恢复默认)
查看core_pattern配置:sysctl -a | grep core_pattern
设置core_pattern配置:sysctl -w kernel.core_pattern=core-%e-%p-%t