LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 08-11-2005, 03:59 AM   #1
phuna
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.

--
phuna
 
Old 08-11-2005, 04:14 AM   #2
fouldsy
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
phuna
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
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
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
phuna
LQ Newbie
 
Registered: Jul 2005
Posts: 13

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

Code:
#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);
    }
  else
    {
      printf("Fail to get resource usage!");
    }
}
 
  


Reply



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

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:58 AM.

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