thread stack pointer

♀尐吖头ヾ 提交于 2019-12-06 04:43:21

问题


In Linux 2.6.32-32, is there a way to find the following information about a thread programmatically in a pthreads program? I need: run count, stack pointer, stack start/end, stack size, stack usage. Something like ThreadX, I guess, but within a program. Thanks.


回答1:


  • pthread_getattr_np() should give you the pthread attributes of a thread
  • pthread_attr_getstack() returns the stack address and size
  • I don't know what you mean by run count.
  • For the stack pointer of a thread different than your current one you might need to use ptrace. Once you have it, you can use it to do the maths for determining how much of the stack is used.

For obtaining your own stack pointer you can always do something along the lines of:

mword sp;
asm volatile ("mov %esp, $0" : "=r"(sp));



回答2:


As an addendum to BjoernD's answer, you can obtain context switch counts and total run time using the getrusage call with RUSAGE_THREAD. You cannot obtain information on the raw number of time slices executed; this information is not tracked in the first place.



来源:https://stackoverflow.com/questions/6700966/thread-stack-pointer

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!