属于不同于进程堆栈的线程的堆栈如何? [英] How is a stack belonging to a thread different from a stack of a process
问题描述
如果我看到 / proc /< p>,那么有人可以告诉我这两种堆栈有什么不同。 pid> / map
和 proc / pid / task /< tid>
我看到了相同的地图。有没有一种方法可以看到属于线程的堆栈(我的意思不是堆栈的进程线程),或者是否有任何gdb命令来查找线程特定的堆栈。
感谢,
Kapil
有没有办法可以看到堆栈属于线程独占
没有这样的事情:所有的线程共享整个地址空间,所以该堆栈不专属于任何给定的线程。事实上,您可以获取一个局部变量的地址,并将该地址传递给另一个线程,然后该线程可以读取或写入值。
我相信你问的是如何判断 / proc /< pid> / maps
中的哪个内存区域是当前正在用作堆栈的线程X?。如果这是个问题,您可以 print $ sp
来找到您感兴趣的线程的当前堆栈指针,然后在 / proc /< pid> / maps
与 $ sp
重叠。
Can anybody please tell me what is the difference b/w the two types of stacks.
If I see /proc/<pid>/map
and proc/pid/task/<tid>
I see same map. Is there a way we can see the stack belonging to thread exclusively (I mean not the stack of process thread) or if there is any gdb command to find out thread specific stack.
Thanks, Kapil
Is there a way we can see the stack belonging to thread exclusively
There is no such thing: all the threads share the entire address space, so the stack doesn't "belong exclusively" to any given thread. In fact, you can take an address of a local variable, and pass that address to a different thread, which can then read or write values to it.
What I believe you are asking is "how to tell which memory region in /proc/<pid>/maps
is thread X currently using as its stack?". If that's the question, you can print $sp
to find out current stack pointer for the thread you are interested in, and then find a region in /proc/<pid>/maps
that overlaps $sp
.
这篇关于属于不同于进程堆栈的线程的堆栈如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!