Linux under the multi-threaded program occurs when Coredump, with
Gdb/path/to/program/file Core
You can see all the threads
[Email protected]:~/test/thread# gdb a.out Core
GNU gdb (GDB) 7.6.1
Copyright (C) Free Software Foundation, Inc.
License gplv3+: GNU GPL version 3 or later This was free software:you was 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 is configured as "I486-slackware-linux".
For bugs reporting instructions, please see:
Reading symbols From/root/test/thread/a.out...done.
[New LWP 826]
[New LWP 825]
But which line friend is the thread that causes Coredump?
Generally available with the Gettid () function, but Gittid will fail to link in the default configuration
This is the system call .
#include <stdio.h> #include <sys/syscall.h>//linux system call for thread Id#include <assert.h># Include <pthread.h>void *nbi (void *arg) { int i; printf ("Child thread lwpid =%u\n", Syscall (Sys_gettid)); printf ("Child thread tid =%u\n", pthread_self ()); scanf ("%d", i);//code Dump}int Main () { pthread_t tid; int RC; printf ("main thread lwpid =%u\n", Syscall (Sys_gettid)); printf ("main thread tid =%u\n", pthread_self ()); rc = pthread_create (&tid, NULL, NBI, NULL); ASSERT (0 = = RC); Pthread_join (Tid, NULL); return 0;}
Operation Result:
[Email protected]:~/test/thread#./a.out
Main thread lwpid = 825
Main thread tid = 3076090112
Child thread Lwpid = 826
Child thread tid = 3076086592
12
Segmentation fault (core dumped)
Coredump Reason:
(GDB) bt
#0 0xb75ed50e in __gi__io_vfscanf () from/lib/libc.so.6
#1 0xb75fc183 in __isoc99_scanf () from/lib/libc.so.6
#2 0x080486ca in NBI (arg=0x0) at Test.c:12
#3 0xb7728955 in Start_thread () from/lib/libpthread.so.0
#4 0xb767e1ae in Clone () from/lib/libc.so.6
(GDB)
Write data to 0x0000000c (reserved address) causes SIGSEGV
How to get the thread ID under Linux