strace -f -F -o strace.txt /data1/waf/sbin/nginx -c /data1/waf/conf/nginx.conf
如果想讓系統在信號中斷造成的錯誤時產生core文件, 我們需要在shell中按如下設置:
#設置core大小為無限
ulimit -c unlimited
#設置文件大小為無限
ulimit unlimited
gdb /data1/waf/sbin/nginx core.21169
編譯nginx程序-g: 產生調試工具所用的調試符號信息(如果所編譯的程序想要調試就需要加-g),-O, -O2,-O3: 優化編譯連接 是執行的更迅速 -O的優化<-O2的優化<-O3的優化(不加是默認是-O)這個只在你的程序已經確定沒有錯誤,可以發布時才去進行優化 平時就不用了
設置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" > /proc/sys/kernel/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 添加命令名
測試產生core文件:kill -s SIGSEGV $$