linux stack usage
Hi, I'm fairly new to linux but I am a long time programmer.
I'm trying to understand how linux handles stacks. (Assume 2.6.x).
First, I'd like to know how to determine how large a particular process/thread's stack is. I found that I can 'cat /proc/####/status | grep -i vmstk" and get 'a number', but after several tests, I don't trust that this is the stack size. (I've found it hard to get good documentation on what VmStk is...)
Another method I tried to figure out approx how large a default stack is, was this program (reproduced from memory, so might have a few mistakes...) :
---------------------------------------------
void use_more_stack(void)
{
static int total_kb = 0;
char buffer[1024];
memset(buffer, 1, sizeof(buffer));
printf("total: %d KB\n", ++total_kb);
use_more_stack();
}
int main(void)
{
char buffer[1024];
use_more_stack();
return 0;
}
---------------------------------------------
and then just waited for the seg fault or whatever bad thing happened.
Well, this program finally segfaulted after 12 MB (yes megabytes!).
So, can a linux thread have a 12MB stack? Does the stack grow dynamically with use? What's the deal?
Any info would be appreciated.
Thanks.
|