转自:http://blog.youkuaiyun.com/forever_feng/article/details/4676420
1. coredump 产生的原理和局限
1.1. 如何产生 core 文件
要素一,必须有信号产生:
从上面的信号定义和说明可以看出,进程中止前肯定会产生信号,然后内核根据信号的类型来决定是否要产生 core 文件。
要素二,编译器支持:
要产生 core 文件,编译器必须支持把当前进程的镜像以某种格式 dump 到一个文件中,常见的比如 gcc/g++ 的 -g 选项。
要素三,环境参数支持:
通过 ulimit –a 查看 core file size 是否为 0 ,如果为 0 则不能产生 core 文件。
通过 ulimit –c unlimited 可以系统能支持的产生足够大的 core 文件,也可以设置为具体值。
特别说明:
core 文件的产生不是 POSIX.1 所属部分,而是很多 UNIX/Linux 版本的实现特征。
1.2. Unix/Linux 对信号的处理方式
Name |
Description |
ISO C |
SUS |
FreeBSD 5.2.1 |
Linux 2.4.22 |
Mac OS X 10.3 |
Solaris 9 |
Default action |
SIGABRT |
abnormal termination (abort ) |
• |
• |
• |
• |
• |
• |
terminate+core |
SIGALRM |
timer expired (alarm ) |
|
• |
• |
• |
• |
• |
terminate |
SIGBUS |
hardware fault |
|
• |
• |
• |
• |
• |
terminate+core |
SIGCANCEL |
threads library internal use |
|
|
|
|
|
• |
ignore |
SIGCHLD |
change in status of child |
|
• |
• |
• |
• |
• |
ignore |
SIGCONT |
Continue stopped process |
|
• |
• |
• |
• |
• |
continue/ignore |
SIGEMT |
hardware fault |
|
|
• |
• |
• |
• |
terminate+core |
SIGFPE |
arithmetic exception |
• |
• |
• |
• |
• |
• |
terminate+core |
SIGFREEZE |
checkpoint freeze |
|
|
|
|
|
• |
ignore |
SIGHUP |
hangup |
|
• |
• |
• |
• |
• |
terminate |
SIGILL |
illegal instruction |
• |
• |
• |
• |
• |
• |
terminate+core |
SIGINFO |
status request from keyboard |
|
|
• |
|
• |
|
ignore |
SIGINT |
terminal interrupt character |
• |
• |
• |
• |
• |
• |
terminate |
SIGIO |
asynchronous I/O |
|
|
• |
• |
• |
• |
terminate/ignore |
SIGIOT |
hardware fault |
|
|
• |
• |
• |
• |
terminate+core |
SIGKILL |
termination |
|
• |
• |
• |
• |
• |
terminate |
SIGLWP |
threads library internal use |
|
|
|
|
|
• |
ignore |
SIGPIPE |
write to pipe with no readers |
|
• |
• |
• |
• |
• |
terminate |
SIGPOLL |
pollable event (poll ) |
|
XSI |
|
• |
|
• |
terminate |
SIGPROF |
profiling time alarm (setitimer ) |
|
XSI |
• |
• |
• |
• |
terminate |
SIGPWR |
power fail/restart |
|
|
|
• |
|
• |
terminate/ignore |
SIGQUIT |
terminal quit character |
|
• |
• |
• |
• |
• |
terminate+core |
SIGSEGV |
invalid memory reference |
• |
• |
• |
• |
• |
• |
terminate+core |
SIGSTKFLT |
coprocessor stack fault |
|
|
|
• |
|
|
terminate |
SIGSTOP |
stop |
|
• |
• |
• |
• |
• |
stop process |
SIGSYS |
invalid system call |
|
XSI |
• |
• |
• |
• |
terminate+core |
SIGTERM |
termination |
• |
• |
• |
• |
• |
• |
terminate |
SIGTHAW |
checkpoint thaw |
|
|
|
|
|
• |
ignore |
SIGTRAP |
hardware fault |
|
XSI |
• |
• |
• |
• |
terminate+core |
SIGTSTP |
terminal stop character |
|
• |
• |
• |
• |
• |
stop process |
SIGTTIN |
background read from control tty |
|
• |
• |
• |
• |
• |
stop process |
SIGTTOU |
background write to control tty |
|
• |
• |
• |
• |
• |
stop process |
SIGURG |
urgent condition (sockets) |
|
• |
• |
• |
• |
• |
ignore |
SIGUSR1 |
user-defined signal |
|
• |
• |
• |
• |
• |
terminate |
SIGUSR2 |
user-defined signal |
|
• |
• |
• |
• |
• |
terminate |
SIGVTALRM |
virtual time alarm (setitimer ) |
|
XSI |
• |
• |
• |
• |
terminate |
SIGWAITING |
threads library internal use |
|
|
|
|
|
• |
ignore |
SIGWINCH |
terminal window size change |
|
|
• |
• |
• |
• |
ignore |
SIGXCPU |
CPU limit exceeded (setrlimit ) |
|
XSI |
• |
• |
• |
• |
terminate+core/ignore |
SIGXFSZ |
file size limit exceeded (setrlimit ) |
|
XSI |
• |
• |
• |
• |
terminate+core/ignore |
SIGXRES |
resource control exceeded |
|
|
|
|
|
• |
ignore |