Linux C:core Dump

Source: Internet
Author: User

1. Core dump file system settings http://www.cnblogs.com/no7dw/archive/2013/02/18/2915819.html

You will need to enter-G at compile time to generate the Coredump file:

GCC-G-O test test.c

Build switch and size limit for core files:

1) Use the ULIMIT-C command to view the build switch for the core file. If the result is 0, this feature is turned off and the core file is not generated.

2) Use the ulimit-c filesize command to limit the size of the core file

Ulimit-c Unlimited does not limit core file size

How to use the core file:
Under Linux, use:
#gdb-C Core.pid program_name
You can enter GDB mode.
Input where, you can indicate which line is down, which function, who is called and so on.
(GDB) where
or enter BT.
(GDB) bt

Pstack can also view coredump files;

2. causes of coredump and several situations http://blog.chinaunix.net/uid-20671208-id-4910096.html

The general process generates COREDUMP because the process receives a segmentfault signal, at this time, the process will coredump, the signal is SIGSEGV, generally seen in the program is received signal number 11th. It is the SIGSEGV signal. Like what:

Several of them may be produced:

2.1 Memory access out of bounds

A) array subscript access is out of bounds, including, of course, the container subscript access across the STL.

b) When traversing a string, rely on the string terminator to determine whether the string ends, but the string does not have a normal use terminator.

c) Use strcpy, strcat, sprintf, strcmp,strcasecmp and other string manipulation functions to write the target string out of bounds. You should use strncpy, strlcpy, Strncat, Strlcat, snprintf, strncmp, strncasecmp, and other functions to prevent read and write out of bounds.

2.2 Multithreaded threads use a thread-unsafe function.

You should use the following thread-safe functions, which are easily used incorrectly: Asctime_r (3c) Gethostbyname_r (3n) getservbyname_r (3n) ctermid_r (3s) gethostent_r (3n) Getservbyport_r (3n) Ctime_r (3c) Getlogin_r (3c) Getservent_r (3n) Fgetgrent_r (3c) Getnetbyaddr_r (3n) Getspent_r (3c) Fgetpwent_r (3c) Getnetbyname_r (3n) Getspnam_r (3c) Fgetspent_r (3c) Getnetent_r (3n) Gmtime_r (3c) Gamma_r (3m) Getnetgrent_r (3n) lgamma_r (3m) Getauclassent_r (3) getprotobyname_r (3n) Localtime_r (3c) Getauclassnam_r (3) Etprotobynumber_r (3n) nis_sperror_r (3n) Getauevent_r (3) getprotoent_r (3n) Rand_r (3c) Getauevnam_r (3) Getpwent_r (3c) Readdir_r (3c) Getauevnum_r (3) Getpwnam_r (3c) Strtok_r (3c) Getgrent_r (3c) Getpwuid_r (3c) Tmpnam_r (3s) getgrgid_r (3c) Getrpcbyname_r (3n) Ttyname_r (3c) Getgrnam_r (3c) Getrpcbynumber_r (3n) gethostbyaddr_r (3n) Getrpcent_r (3n), A document for a list of thread-safe functions on a network.

2.3 Multi-thread read-write variable data is not locked for protection. For example, global variables, static variables, and so on.

For global data that will be accessed by multiple threads at the same time, you should pay attention to lock protection, otherwise it is easy to cause coredump

2.4 Illegal pointers, including null pointers, invalid pointer conversions, wild pointers, and structural byte alignment issues in cross-platform products.

2.5 Stack Overflow. In particular, the embedded system, the stack is relatively small, it is easy to overflow.

2.6 By the way, there are several situations that do not produce coredump:

The core file won't be generated if

(a) The process was Set-user-id and the current user are not the owner of the program file, or

(b) The process was Set-group-id and the current user are not the group owner of the file,

(c) The user does not having permission to write in the current working directory,

(d) The file already exists and the user does not having permission to write to it, or

(e) The file is too big (recall the Rlimit_core limit in section 7.11). The permissions of the core file (assuming that the file doesn ' t already exist) is usually User-read and User-write, Alth Ough Mac OS X sets only user-read.

Linux C:core dump

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.