轉自:http://andyniu.iteye.com/blog/1965571
core dump的概念:
A core dump is the recorded state of the working memory of a computer program at a specific time, generally when the program has terminated abnormally (crashed). In practice, other key pieces of program state are usually dumped at the same time, including the processor registers, which may include the program counter and stack pointer, memory management information, and other processor and operating system flags and information. The name comes from the once-standard memory technology core memory. Core dumps are often used to diagnose or debug errors in computer programs.
On many operating systems, a fatal error in a program automatically triggers a core dump, and by extension the phrase "to dump core" has come to mean, in many cases, any fatal error, regardless of whether a record of the program memory is created.
在linux平台下,設定core dump檔案產生的方法:
linux coredump調試 1 )如何產生 coredump 檔案 ? 登陸 LINUX 伺服器,任意位置鍵入 echo "ulimit -c 1024" >> /etc/profile 退出 LINUX 重新登陸 LINUX 鍵入 ulimit -c 如果顯示 1024 那麼說明 coredump 已經被開啟。 1024 限制產生的 core 檔案的大小不能超過 1024kb,可以使用參數unlimited,取消該限制 ulimit -c unlimited 2 ) . core 檔案的簡單介紹 在一個程式崩潰時,它一般會在指定目錄下產生一個 core 檔案。 core 檔案僅僅是一個記憶體映象 ( 同時加上調試資訊 ) ,主要是用來調試的。 3 ) . 開啟或關閉 core 檔案的產生 用以下命令來阻止系統產生 core 檔案 : ulimit -c 0 下面的命令可以檢查產生 core 檔案的選項是否開啟 : ulimit -a 該命令將顯示所有的使用者定製,其中選項 -a 代表“ all ”。 也可以修改系統檔案來調整 core 選項 在 /etc/profile 通常會有這樣一句話來禁止產生 core 檔案,通常這種設定是合理的 : # No core files by default ulimit -S -c 0 > /dev/null 2>&1 但是在開發過程中有時為了調試問題,還是需要在特定的使用者環境下開啟 core 檔案產生的設定。 在使用者的 ~/.bash_profile 裡加上 ulimit -c unlimited 來讓特定的使用者可以產生 core 檔案。 如果 ulimit -c 0 則也是禁止產生 core 檔案,而 ulimit -c 1024 則限制產生的 core 檔案的大小不能超過 1024kb 4 ) . 設定 Core Dump 的核心轉儲檔案目錄和命名規則 /proc/sys/kernel/core_uses_pid 可以控制產生的 core 檔案的檔案名稱中是否添加 pid 作為擴充 ,如果添加則檔案內容為 1 ,否則為 0 proc/sys/kernel/core_pattern 可以設定格式化的 core 檔案儲存位置或檔案名稱 ,比如原來檔案內容是 core-%e 可以這樣修改 : 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 添加命令名 6 ) . 一個小方法來測試產生 core 檔案 直接輸入指令 : kill -s SIGSEGV $$ 如何產生Core Dump
發生doredump一般都是在進程收到某個訊號的時候,Linux上現在大概有60多個訊號,可以使用 kill -l 命令全部列出來。
sagi@sagi-laptop:~$ kill -l 1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGTRAP 6) SIGABRT 7) SIGBUS 8) SIGFPE 9) SIGKILL 10) SIGUSR1 11) SIGSEGV 12) SIGUSR2 13) SIGPIPE 14) SIGALRM 15) SIGTERM 16) SIGSTKFLT 17) SIGCHLD 18) SIGCONT 19) SIGSTOP 20) SIGTSTP 21) SIGTTIN 22) SIGTTOU 23) SIGURG 24) SIGXCPU 25) SIGXFSZ 26) SIGVTALRM 27) SIGPROF 28) SIGWINCH 29) SIGIO 30) SIGPWR 31) SIGSYS 34) SIGRTMIN 35) SIGRTMIN+1 36) SIGRTMIN+2 37) SIGRTMIN+3 38) SIGRTMIN+4 39) SIGRTMIN+5 40) SIGRTMIN+6 41) SIGRTMIN+7 42) SIGRTMIN+8 43) SIGRTMIN+9 44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+13 48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14 51) SIGRTMAX-13 52) SIGRTMAX-12 53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9 56) SIGRTMAX-8 57) SIGRTMAX-7 58) SIGRTMAX-6 59) SIGRTMAX-5 60) SIGRTMAX-4 61) SIGRTMAX-3 62) SIGRTMAX-2 63) SIGRTMAX-1 64) SIGRTMAX
針對特定的訊號,應用程式可以寫對應的訊號處理函數。如果不指定,則採取預設的處理方式, 預設處理是coredump的訊號如下:
3)SIGQUIT 4)SIGILL 6)SIGABRT 8)SIGFPE 11)SIGSEGV 7)SIGBUS 31)SIGSYS5)SIGTRAP 24)SIGXCPU 25)SIGXFSZ 29