Review your favorite Linux distribution.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 08-11-2005, 03:59 AM   #1
LQ Newbie
Registered: Jul 2005
Posts: 13

Rep: Reputation: 0
How to get current stack usage

Hi all,
I'm programming in Linux, is there any way to get current stack usage of a thread (it's stack usage, not the stack size), means that how much stack space that all local variables, function return addresses, etc. use at a the moment?
Sorry for my bad English.
Any help would be appreciated.

Old 08-11-2005, 04:14 AM   #2
Senior Member
Registered: Jan 2002
Location: St Louis, MO
Distribution: Ubuntu
Posts: 1,284

Rep: Reputation: 47
What language are you scripting/programming this in? Might help.
Old 08-11-2005, 08:19 AM   #3
LQ Newbie
Registered: Jul 2005
Posts: 13

Original Poster
Rep: Reputation: 0
Thanks for your reply, I'm using C
Old 08-11-2005, 09:19 AM   #4
jim mcnamara
Registered: May 2002
Posts: 964

Rep: Reputation: 34
The only available system call is getrusage().
It may not give you what you need, but it will indicate if you are near to crashing into limits.
Old 08-11-2005, 09:25 PM   #5
LQ Newbie
Registered: Jul 2005
Posts: 13

Original Poster
Rep: Reputation: 0
I've tried getrusage, but it returns zero for stack usage!

#include <sys/time.h>
#include <sys/resource.h>
#include <unistd.h>
#include <stdio.h>

int main()
  int a = 0xabcd;
  int b = 0x12345678;
  unsigned short c = 0xff;
  int ret;
  struct rusage usage;

  ret = getrusage(RUSAGE_SELF, &usage);
  if (ret == 0)
      printf("Stack usage: %d\n", usage.ru_isrss);
      printf("Fail to get resource usage!");


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 Off
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
getting realtime info on memory usage-cpu and harddrive usage steering Linux - Newbie 5 03-03-2005 08:43 PM
ndiswrapper usage under Slackware current planetes Linux - Wireless Networking 2 11-07-2004 11:04 AM
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
one-liner to see current internet bandwidth usage doorbits Debian 6 11-01-2003 02:10 PM

All times are GMT -5. The time now is 03:33 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