Вопрос

I want to kill a specific thread in gdb. This is how I attach a program to gdb.

(gdb) r ./bin/myProg arg1 arg2

I get the current running threads by

(gdb) info threads
    3 Thread 0x7ffff61fe700 (LWP 28549)  0x000000323b6db7ad in foo () from /lib64/libc.so.6
  * 2 Thread 0x7ffff6bff700 (LWP 28548)  bar () at ./src/myProg.c:229
    1 Thread 0x7ffff7506740 (LWP 28547)  0x000000323be0822d in pthread_join () from /lib64/libpthread.so.0

This is how I tried to kill a thread (say thread 3)

(gdb)t 3
[Switching to thread 3 (Thread 0x7ffff61fe700 (LWP 28549))]#0  foo () at ./src/myProg.c:288
(gdb)call raise(3,0)

Here I assumed the signature of raise as raise(threadId as displayed in the gdb, signo as 0)

But the thread is not getting killed. Should I use a different signo or is the thread id wrong?

Note: I read this question in SO but that did not help me

Это было полезно?

Решение

Signal handling in multithreaded apps is generally complicated. Thus, it makes more sense to just switch into the thread, make sure it is not holding any resources (such as locked mutexes) and then simply invoke pthread_exit() on its behalf as if it exited on its own accord.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top