Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

thread stack pointer

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.

like image 443
Dervin Thunk Avatar asked Dec 28 '22 17:12

Dervin Thunk


1 Answers

  • 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));
like image 137
BjoernD Avatar answered Jan 10 '23 13:01

BjoernD