LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-17-2011, 04:17 AM   #1
sudhakar1287
LQ Newbie
 
Registered: Apr 2011
Posts: 1

Rep: Reputation: 0
how do i get stack size of running process?


hi to all .
Can anyone tell me that how to get information about stack, allocated by kernel to a running process ?

for this ,is there any api function,any system call is available in ubuntu 8.04 ?


i've tried following command

man getrlimit but there no manual entry for this.

i'm using ubuntu 8.04.
thanks in advance.

Last edited by sudhakar1287; 04-17-2011 at 04:28 AM. Reason: for better understanding
 
Old 04-17-2011, 08:49 AM   #2
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181
The command
ulimit -s
tells you how much address space is allocated for each process's primary stack. The result is given in KB.

For a specific process that is already running, you might attach a debugger to it to see the current stack use.

You could also use the command
grep -A 1 stack /proc/pid/smaps

replacing pid with the pid of the process you want.

I think that tells you either how much stack space has actually been used (rounded up to a multiple of 4KB) or a minimum value if very little stack has been used.

If you need more detail for small stack use, change the 1 in that command to 2 and look at the Rss value. For a fairly new process with low stack use on a system that isn't under serious memory load, the Rss value should be the true stack usage rounded up to 4KB multiple, while Size would be the minimum initial mapping.

I only tried that last command on a 64 bit Centos 5 and only on a few processes. So it might need some details changed to handle other distributions.

Last edited by johnsfine; 04-17-2011 at 08:58 AM.
 
Old 04-17-2011, 09:20 AM   #3
T3RM1NVT0R
Senior Member
 
Registered: Dec 2010
Location: Internet
Distribution: Linux Mint, SLES, CentOS, Red Hat
Posts: 2,385

Rep: Reputation: 476Reputation: 476Reputation: 476Reputation: 476Reputation: 476
@ Reply

Just giving an example let me know if I am getting it right

ps -eaf | grep firefox

root 2255 1935 0 15:58 ? 00:00:00 /bin/sh /usr/lib/firefox-3.6.13/firefox

top -p 2255

Tasks: 1 total, 0 running, 1 sleeping, 0 stopped, 0 zombie
Cpu(s): 2.2%us, 2.2%sy, 0.0%ni, 95.7%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 3344308k total, 1043640k used, 2300668k free, 208524k buffers
Swap: 3999740k total, 0k used, 3999740k free, 516932k cached

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
2255 root 20 0 1896 512 440 S 0 0.0 0:00.00 firefox
 
0 members found this post helpful.
  


Reply


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
Find the dynamic stack and heap size of a running process in rhel marifran Red Hat 5 08-31-2010 03:15 AM
single 8K process stack vs 4K process stack and a seperate 4K interrupt stack charvak Linux - Kernel 1 03-17-2010 07:58 PM
Get Process size and Thread count for a particular running process haseit Linux - Newbie 2 01-23-2009 12:09 AM
Getting the stack size of a process aravinda78 Programming 4 12-12-2008 09:32 AM


All times are GMT -5. The time now is 02:48 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration