属于不同于进程堆栈的线程的堆栈如何? [英] How is a stack belonging to a thread different from a stack of a process

查看:144
本文介绍了属于不同于进程堆栈的线程的堆栈如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



如果我看到 / 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆