On Sun, Oct 07, 2007 at 11:57:57AM +0200, Mike Kemelmakher wrote: > The pthread_attr_getstacksize() and pthread_attr_setstacksize() > functions, respectively, shall get > > and set the thread _*creation*_ stacksize attribute in the attr > object. > > What i need is current stack size of a running thread. My problem > is that i have a thread with constantly growing stack ( i can see it > via /proc/PID/smaps ). Thread uses some functions from a > proprietary shared library. I need to know when the stack size of > the mentioned thread reaches RLIMIT_STACK so i can safely restart > that thread before it crashes.
Ah, good point. I don't believe this is explicitly tracked, since the stack segment grows automatically. Here's how I would do it, assuming you can run code in the context of that thread: get the base of the stack (initial address) using pthread_attr_getstackaddr or pthread_attr_getstack, get the current value of the stack pointer via inline assembly or just creating a variable on the stack and taking its address, and then substract the former from the latter. Take into account that the stack may grow up or down, depending on architecture. The value you get back is the current size of the stack. Cheers, Muli -- SYSTOR 2007 --- 1st Annual Haifa Systems and Storage Conference 2007 http://www.haifa.il.ibm.com/Workshops/systor2007/ Virtualization workshop: Oct 29th, 2007 | Storage workshop: Oct 30th, 2007 ================================================================= To unsubscribe, send mail to [EMAIL PROTECTED] with the word "unsubscribe" in the message body, e.g., run the command echo unsubscribe | mail [EMAIL PROTECTED]
