歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux管理 >> Linux服務 >> C++程序作為Linux服務啟動時出core的位置

C++程序作為Linux服務啟動時出core的位置

日期:2017/3/1 9:52:14   编辑:Linux服務

C++程序作為Linux服務啟動時出core的位置

首先,要確保生成core,需要運行命令

ulimit -c unlimited

這個在腳本中設置還是很簡單的,比如在/etc/init.d/data_service腳本中:

PROGRAM=/home/dist/tcp/data_service_d


test -x $PROGRAM || exit 0

case "$1" in
start)
log_begin_msg "Starting data service"
ulimit -c unlimited
$PROGRAM /home/dist/tcp/config.xml &
cd -
log_end_msg 0
;;
stop)
PID=`pidof data_service_d`
log_begin_msg "Stopping data service"
if [ ! -z "$PID" ]; then
kill -15 $PID
fi
log_end_msg 0
;;
restart)
$0 stop
$0 start
;;
*)
log_success_msg "Usage: service data_service {start|stop|restart}"
exit 1
esac

exit 0

但是很快就發現,core文件的位置不在/home/dist/tcp目錄下,而是在/ 目錄下。

這是通過pidof data_service_d 找到進程id,然後查到cwd鏈接指向的是/

ot@vm6:/# pidof data_service_d
12326
root@vm6:/# ls /proc/12326/cwd -alh
lrwxrwxrwx 1 root root 0 Sep 24 11:41 /proc/12326/cwd -> /

更多詳情請繼續閱讀第2頁的內容:http://www.linuxidc.com/Linux/2013-10/91322p2.htm

Copyright © Linux教程網 All Rights Reserved