coreÎļþµÄ¼òµ¥½éÉÜ
ÔÚÒ»¸ö³ÌÐò±ÀÀ£Ê±£¬ËüÒ»°ã»áÔÚÖ¸¶¨Ä¿Â¼ÏÂÉú³ÉÒ»¸öcoreÎļþ¡£coreÎļþ½ö½öÊÇÒ»¸öÄÚ´æÓ³Ïó(ͬʱ¼ÓÉϵ÷ÊÔÐÅÏ¢)£¬Ö÷ÒªÊÇÓÃÀ´µ÷ÊԵġ£
¿ªÆô»ò¹Ø±Õ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
ÉèÖÃ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-ʱ¼ä´Á
ÒÔÏÂÊDzÎÊýÁбí:ËÑË÷
%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ÎļþÔÚcoreÎļþËùÔÚĿ¼Ï¼üÈë:
gdb -c core |
Ëü»áÆô¶¯GNUµÄµ÷ÊÔÆ÷£¬À´µ÷ÊÔcoreÎļþ£¬²¢ÇÒ»áÏÔʾÉú³É´ËcoreÎļþµÄ³ÌÐòÃû£¬ÖÐÖ¹´Ë³ÌÐòµÄÐźŵȵÈ
Èç¹ûÄãÒѾ֪µÀÊÇÓÉʲô³ÌÐòÉú³É´ËcoreÎļþµÄ£¬±ÈÈçMyServer±ÀÀ£ÁËÉú³Écore.12345£¬ÄÇôÓôËÖ¸Áîµ÷ÊÔ:
gdb -c core MyServer |
ÒÔÏÂÔõô°ì¾Í¸ÃȥѧϰgdbµÄʹÓÃÁË
Ò»¸öС·½·¨À´²âÊÔ²úÉúcoreÎļþ
Ö±½ÓÊäÈëÖ¸Áî:
kill -s SIGSEGV $$ |
ΪºÎÓÐʱ³ÌÐòDownÁË£¬È´Ã»Éú³É CoreÎļþ¡£
LinuxÏ£¬ÓÐһЩÉèÖ㬱êÃ÷ÁËresources available to the shell and to processes¡£¿ÉÒÔʹÓÃ
#ulimit -a À´¿´ÕâЩÉèÖᣠ(ulimitÊÇbash built-in Command)
-a All current limits are reported -c The maximum size of core files created -d The maximum size of a processîØ™s data segment -e The maximum scheduling priority ("nice") -f The maximum size of files written by the shell and its children -i The maximum number of pending signals -l The maximum size that may be locked into memory -m The maximum resident set size (has no effect on Linux) -n The maximum number of open file descriptors (most systems do not allow this value to be set) -p The pipe size in 512-byte blocks (this may not be set) -q The maximum number of bytes in POSIX message queues -r The maximum real-time scheduling priority -s The maximum stack size -t The maximum amount of cpu time in seconds -u The maximum number of processes available to a single user -v The maximum amount of virtual memory available to the shell -x The maximum number of file locks
|
´ÓÕâÀï¿ÉÒÔ¿´³ö£¬Èç¹û -cÊÇÏÔʾ£ºcore file size (blocks, -c)
Èç¹ûÕâ¸öֵΪ0£¬ÔòÎÞ·¨Éú³ÉcoreÎļþ¡£ËùÒÔ¿ÉÒÔʹÓãº
#ulimit -c 1024 »òÕß #ulimit -c unlimited À´Ê¹ÄÜ coreÎļþ¡£
Èç¹û³ÌÐò³ö´íʱÉú³ÉCore Îļþ£¬Ôò»áÏÔʾSegmentation fault (core dumped)¡£
Core DumpµÄºËÐÄת´¢ÎļþĿ¼ºÍÃüÃû¹æÔò:
/proc/sys/kernel/core_uses_pid¿ÉÒÔ¿ØÖƲúÉúµÄcoreÎļþµÄÎļþÃûÖÐÊÇ·ñÌí¼Ópid×÷ΪÀ©Õ¹£¬Èç¹ûÌí¼ÓÔòÎļþÄÚÈÝΪ1£¬·ñÔòΪ0