Visit the LQ Articles and Editorials section
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 01-07-2007, 08:02 PM   #1
LQ Newbie
Registered: Jan 2007
Posts: 7

Rep: Reputation: 0
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);


int main(void)
char buffer[1024];
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.

Old 01-08-2007, 04:58 AM   #2
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 30
It looks as though the kernel you're running allows a 12MB stack. Linux does expand the stack space as needed.

For more information:

Hope this helps.
Old 05-11-2009, 01:51 PM   #3
LQ Newbie
Registered: May 2009
Posts: 1

Rep: Reputation: 0
For anyone reviewing this thread, note also, that the stack size in this case was for a single threaded program. Stack size allocated to additional threads would likely be much smaller, and would be bounded by its stack address and the previous stacks address. The first threads stack is, if I understand correctly, only bounded when it starts to run into stuff in the application space that sits underneath it.


kernel, size, stack

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Difference b/t Kernel stack and User stack hazzyb Linux - Software 2 09-29-2008 07:40 PM
Stack usage of an application tsenthilt Linux - Software 5 05-14-2006 10:09 AM
How to get current stack usage phuna Programming 4 08-11-2005 09:25 PM
how to determine cpu usage, memory usage, I/O usage by a particular user logged on li rags2k Programming 4 08-21-2004 04:45 AM

All times are GMT -5. The time now is 05:34 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration