使用shell控制core文件使用

1.core文件控制脚本


#use "source core.sh start" to start use coredump
#use "source core.sh stop" to stop coredump
#use -g to compile the source file
#use gdb -c corefile to watch corefile
#use where or bt to see the seg fault
#
#!/bin/sh
if [ ! -f ~/.bash_profile.bak ];then
    cp ~/.bash_profile ~/.bash_profile.bak
fi
if [ $1 == "start" ];then
    echo $(pwd)/"core-%e-%p-%t" > /proc/sys/kernel/core_pattern
    echo "1" > /proc/sys/kernel/core_uses_pid
    if [ -f ~/.bash_profile.bak ];then
        rm -rf ~/.bash_profile
        cp ~/.bash_profile.bak ~/.bash_profile
        echo "ulimit -c unlimited" >> ~/.bash_profile
    fi
    echo "coredump is started"
fi
if [ $1 == "stop" ];then
    echo "core" > /proc/sys/kernel/core_pattern
    echo "0" > /proc/sys/kernel/core_uses_pid
    if [ -f ~/.bash_profile.bak ];then
        rm -rf ~/.bash_profile
        cp ~/.bash_profile.bak ~/.bash_profile
        echo "ulimit -c 0" >> ~/.bash_profile
    fi
    echo "coredump is stoped"
fi
source ~/.bash_profile

2.core文件命令

source core.sh start

source core.sh stop