Linux thread Debug Ulimit core

Source: Internet
Author: User

In Linux under the thread of the programming of the students are expected to find a bug found crash, multi-threaded case of the bug tracking is not easy.

Now let me introduce a handy way to Ulimit core.

Let's start with a brief introduction to what Ulimit is (you can also man ulimit to see for yourself).


"' When some of the programs in the system encounter some errors and crash, the system automatically generates core file records crash time system information, including memory and register information, which can be used by programmers in future Debug. These errors include segment errors, illegal instructions, bus errors, or user-generated exit information, and so on, in general, the core file is stored in the current folder.

But why don't we usually see the core file? That's because your system sets the size of the core file to 0. If you need to debug with a core file, you can set the core file size unlimited with Ulimit-c unlimited.

The other parameters are as follows:

<span style= "FONT-SIZE:18PX;" > Parameter:   -a displays the current resource limit settings. -    C <core file Cap > set the maximum value of the core file, in chunks. -    D < data section size > Maximum value of the Program Data section, in kilobytes. -    F < file size > The largest file the shell can create, in chunks. -    h sets the hard limit for the resource, which is the limit set by the administrator. -    m < memory size > Specifies the maximum amount of memory that can be used, in kilobytes.    -N < number of files > specifies the maximum number of files that can be opened at the same time. -    p < buffer size > Specifies the size of the pipe buffer, in 512 bytes. -    s < stack size > specifies the upper limit of the stack in kilobytes.    -S sets the elastic limit for the resource. -    t <cpu time > Specifies the maximum CPU usage time in seconds.    -U < number of programs > number of programs the user can open. -    v < virtual memory size > Specifies the maximum amount of virtual memory that can be used, in kilobytes. </span>


You can use Ulimit-a to view all information:

<span style= "FONT-SIZE:18PX;"             >core file Size (blocks,-c) unlimiteddata seg size (Kbytes,-D) unlimitedscheduling priority       (-e) 0file size (blocks,-f) unlimitedpending signals (-i) 139264max locked memory            (Kbytes,-L) 32max memory size (Kbytes,-m) unlimitedopen files (-N) 1024pipe size              (bytes,-p) 8POSIX message queues (bytes,-Q) 819200real-time priority (-R) 0stack size (Kbytes,-s) 10240cpu time (seconds,-t) Unlimitedmax user processes (-u) 139264virtual mem Ory (Kbytes,-V) unlimitedfile locks (-X) unlimited[[email protected] online_install]$           Ulimit-c 0[[email protected] online_install]$ ulimit-acore file size (blocks,-c) 0data seg size (Kbytes,-D) unlimitedscheduling priority (-e) 0file size (blocks,-f) unlimitedpending Signals (-i) 139264max locked memory (Kbytes,-L) 32max memory size (Kbytes,-m) Unlimitedo Pen files (-N) 1024pipe size (bytes,-p) 8POSIX message queues (bytes,-Q) 819200r Eal-time Priority (-R) 0stack size (Kbytes,-s) 10240cpu time (seconds,-T) Unlimi                      Tedmax User Processes (-u) 139264virtual memory (Kbytes,-V) unlimitedfile locks (-X) unlimited</span>


Sometimes the core file may not appear in your current folder when you have an error, for two reasons: one is that the current terminal is set to not eject the core file, and the other is that the core file is assigned a path. In addition to setting the size of the core file, you can also specify the name of the core file. This setting is to modify the two files for/proc/sys/kernel/core_pattern and/proc/sys/kernel/core_uses_pid. Here are some ways to change these two files:

echo <pattern> >/proc/sys/kernel/core_pattern

echo < "0"/"1" >/proc/sys/kernel/core_uses_pid

Also note that only Superuser can modify these two tables. ’”


When you get the core file, you can use GDB to debug it!
GDB EXE (your executable program)./core.pid (Core file)
Go in, use BT to see the situation of the dead stack, eliminating the endless debugging tracking, is not very convenient ~.

Then use the frame command.
There is a thread in it to stop, and not die, this is generally a deadlock or a message to accept the timeout problem (heard that, not met). In this case, you can use:
gcore pid (PID number of the debug process)
Manually generate the core file, using Pstack (which looks bad on Linux) to view the stack. If you can not see it, look at the code carefully to see if it is in the If,return,break,continue this statement operation is to forget to unlock, as well as nested lock problem, need to be analyzed clearly.


With this method, multi-threaded debugging is no longer a headache!

Reference http://www.cnblogs.com/qq78292959/archive/2012/05/08/2490443.html

Linux thread Debug Ulimit core

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.