永久设置, 修改/etc/sysctl.conf配置文件,添加一行:
kernel.core_pattern= /data01/corefiles/core_%e_%u_%t_%s.%p
然后执行sysctl -p。
3. core文件是否带pid: 修改/proc/sys/kernel/core_uses_pid
如果这个文件的内容被配置成1,那么即使core_pattern中没有设置%p,最后生成的core dump文件名仍会加上进程ID。
永久设置, 修改/etc/sysctl.conf配置文件,添加一行:
kernel.core_uses_pid = 1
然后执行sysctl -p。
4. 使用core文件
在core文件所在目录下键入:
gdb -c core
它会启动GNU的调试器,来调试core文件,并且会显示生成此core文件的程序名,中止此程序的信号等等
如果你已经知道是由什么程序生成此core文件的,比如MyServer崩溃了生成core.12345,那么用此指令调试:
gdb -c core MyServer
5. 一个小方法来测试产生core文件
kill -s SIGSEGV $$
查看生成的core文件:
[root@localhost tmp]# gdb -c core_bash_0_1498014539_11.99469 GNU gdb (GDB) Red Hat Enterprise Linux (7.2-92.el6) Copyright (C) 2010 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-redhat-linux-gnu". For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>. Missing separate debuginfo for the main executable file Try: yum --enablerepo='*-debug*' install /usr/lib/debug/.build-id/e7/124dc03566f456ba8e4a88850251818d64b178 [New Thread 99469] Core was generated by `-bash'. Program terminated with signal 11, Segmentation fault. #0 0x000000317a232777 in ?? ()
查看上面倒数三行:
Core was generated by `-bash'. Program terminated with signal 11, Segmentation fault. #0 0x000000317a232777 in ?? ()
core文件是由bash产生的,是由于接收到信号11产生了段错误。
这里是执行上面bash命令产生的,发送的SIGSEGV信号,而该信号的作用是Invalid memory reference,内存引用异常。由于是bash引起的,所以外部表现会是当前会话中断。
注:
1、下面是列举的信号对应数值及含义:
Signal Value Action Comment ---------------------------------------------------------------------- SIGHUP 1 Term Hangup detected on controlling terminal or death of controlling process SIGINT 2 Term Interrupt from keyboard SIGQUIT 3 Core Quit from keyboard SIGILL 4 Core Illegal Instruction SIGABRT 6 Core Abort signal from abort(3) SIGFPE 8 Core Floating point exception SIGKILL 9 Term Kill signal SIGSEGV 11 Core Invalid memory reference SIGPIPE 13 Term Broken pipe: write to pipe with no readers SIGALRM 14 Term Timer signal from alarm(2) SIGTERM 15 Term Termination signal SIGUSR1 30,10,16 Term User-defined signal 1 SIGUSR2 31,12,17 Term User-defined signal 2 SIGCHLD 20,17,18 Ign Child stopped or terminated SIGCONT 19,18,25 Cont Continue if stopped SIGSTOP 17,19,23 Stop Stop process SIGTSTP 18,20,24 Stop Stop typed at tty SIGTTIN 21,21,26 Stop tty input for background process SIGTTOU 22,22,27 Stop tty output for background process
2、/etc/security/limits.conf文件中soft、hard的区别:
至于limits.conf文件中含义:
# End of file @users soft nofile 100001 @users hard nofile 100002 @root soft nofile 100001 @root hard nofile 100002
@users 用户组 (@+组名形式); soft/hard (限制类型 soft 警告数 ,hard 严格限制数);nofile 限制对象(nofile 文件数,nproc的话就是进程数 );100001 ,限制值。
限制对象具体含义如下:
#<item> can be one of the following: # - core - limits the core file size (KB) # - data - max data size (KB) # - fsize - maximum filesize (KB) # - memlock - max locked-in-memory address space (KB) # - nofile - max number of open file descriptors # - rss - max resident set size (KB) # - stack - max stack size (KB) # - cpu - max CPU time (MIN) # - nproc - max number of processes # - as - address space limit (KB) # - maxlogins - max number of logins for this user # - maxsyslogins - max number of logins on the system # - priority - the priority to run user process with # - locks - max number of file locks the user can hold # - sigpending - max number of pending signals # - msgqueue - max memory used by POSIX message queues (bytes) # - nice - max nice priority allowed to raise to values: [-20, 19] # - rtprio - max realtime priority
参考:
http://bbs.chinaunix.net/thread-1999643-1-1.html
http://linux.vbird.org/linux_basic/0320bash.php#variable_ulimit
http://younglibin.iteye.com/blog/1890701
man 7 signal
cat /etc/security/limits.conf