LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 04-16-2014, 07:22 PM   #1
5883
Member
 
Registered: Aug 2004
Posts: 173

Rep: Reputation: 0
How to generate core file when 1 thread dies ?


if you set ulimit, when process dies, you'll get the core file.

But in my case, the main thread of the process is alive, while the other thread dies, no core file.

Any suggestions ?
Thanks !
 
Old 04-18-2014, 08:17 AM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,900
Blog Entries: 13

Rep: Reputation: 4947Reputation: 4947Reputation: 4947Reputation: 4947Reputation: 4947Reputation: 4947Reputation: 4947Reputation: 4947Reputation: 4947Reputation: 4947Reputation: 4947
This works for me, perhaps you can post some data related to your efforts, or cut it down to smaller chunks and run an experiment. I have little thread experience, but a good amount of core file experience, and further was about to suggest that you set the core file limits from within your program using the setrlimit() function; however I searched for a simple pthread example, put an intentional fault within the thread, set my ulimit -c unlimited in my terminal, compiled, ran it, got a core file and verified that the core file backtraces to the error point in the thread.

Here's the example I grabbed, and many thanks to Tim Murphy for writing a simple, good pthread example: PThreads in C - A Minimal Working Example.

What I changed is in the *inc_x() function just after the declaration for int *x_ptr and assignment, I re-assigned x_ptr to be NULL; thus when it would be used, it should cause a core dump:
Code:
/* this function is run by the second thread */
void *inc_x(void *x_void_ptr)
{
    /* increment x to 100 */
    int *x_ptr = (int *)x_void_ptr;
    x_ptr = NULL;               // my change to cause a core file dump
    while(++(*x_ptr) < 100);    // this is line 10 - relevant to the future error
Here's how to compile this, because you'll need both GDB and pthreads, and then run it, and debug it. Note that I named my test file thread.c, commands typed by me have been colored green:
Code:
~/testcode$ gcc -ggdb -o thread -l pthread thread.c

~/testcode$ ulimit -c unlimited

~/testcode$ ./thread

x: 0, y: 0
y increment finished
Segmentation fault (core dumped)

~/testcode$ gdb thread core

GNU gdb (GDB) 7.1-ubuntu
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i486-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from ~/testcode/thread...done.
[New Thread 12949]
[New Thread 12948]

warning: Can't read pathname for load map: Input/output error.
Reading symbols from /lib/tls/i686/cmov/libpthread.so.0...(no debugging symbols found)...done.
Loaded symbols for /lib/tls/i686/cmov/libpthread.so.0
Reading symbols from /lib/tls/i686/cmov/libc.so.6...(no debugging symbols found)...done.
Loaded symbols for /lib/tls/i686/cmov/libc.so.6
Reading symbols from /lib/ld-linux.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib/ld-linux.so.2
Core was generated by `./thread'.
Program terminated with signal 11, Segmentation fault.
#0  0x0804857a in inc_x (x_void_ptr=0xbfe865bc) at thread.c:10
10	    while(++(*x_ptr) < 100);
(gdb) bt
#0  0x0804857a in inc_x (x_void_ptr=0xbfe865bc) at thread.c:10
#1  0xb78aa96e in start_thread () from /lib/tls/i686/cmov/libpthread.so.0
#2  0xb7818a4e in clone () from /lib/tls/i686/cmov/libc.so.6
(gdb)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
kill -3 didn't generate core file on centos5 lwang3rock Linux - Newbie 1 06-20-2013 04:33 PM
data push from box to removable usb drive dies, then dies, then dies again. bodyofabanshee Linux - Server 11 03-15-2012 12:34 PM
Core dump issues. Program crashes but does not generate core dump file sabeel_ansari Programming 1 10-07-2009 05:23 PM
Why program received SIGQUIT quited but did NOT generate the core file ???? cryincold Programming 2 02-27-2008 05:26 AM
eth0 dies on Fedora Core 4 dinolinux Linux - Networking 3 06-26-2005 10:51 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:17 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration