LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 12-09-2009, 12:19 PM   #1
bozox
LQ Newbie
 
Registered: Oct 2008
Posts: 20

Rep: Reputation: 0
/proc/$pid/status vs. system calls


Hi all,

I'm trying to get memory usage of a process from within that process. I'm calling getrusage, but it always returns zero in ru_idrss. The man page says this field is not even maintained under Linux.

So the question is - which syscall does the VmData line in the /proc/$pid/status come from? Thanks in advance...
 
Old 12-09-2009, 01:39 PM   #2
malekmustaq
Senior Member
 
Registered: Dec 2008
Location: root
Distribution: Slackware & BSD
Posts: 1,614

Rep: Reputation: 433Reputation: 433Reputation: 433Reputation: 433Reputation: 433
bosox,

Have you tried--
user@host-$ ps axu
-this should give you an idea how much mem the process uses

or try --$ top
 
Old 12-09-2009, 05:44 PM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 14,839

Rep: Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822
No idea - why not read /proc/<pid>/status directly ?.
 
Old 12-10-2009, 10:05 AM   #4
bozox
LQ Newbie
 
Registered: Oct 2008
Posts: 20

Original Poster
Rep: Reputation: 0
Quote:
read /proc/<pid>/status directly
That's what I ended up doing. Kinda crude, though. What if file format changes? Native datatypes (int, in this case) are good for you.
 
Old 12-10-2009, 05:21 PM   #5
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 14,839

Rep: Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822
/proc is an API. It ain't going to change until a major release comes along - probably not even then. Fields tend to get added, but the fields that exist are (typically) left alone. /proc is not a real filesystem - it's a pseudo f/s that only exists because some kernelspace code decided to expose some (kernel) data. When you read a "file", the data is filled in - at that instant in time, and in response to the act of being read. For your purposes you might be better using /proc/<pid>/statm (or even stat maybe) - note that statm is in pages.
A quick look at (some of) the code indicates that kernel structures are walked to calculate the numbers "on the fly".
 
Old 12-10-2009, 07:24 PM   #6
Web31337
Member
 
Registered: Sep 2009
Location: Russia
Distribution: Gentoo, LFS
Posts: 399
Blog Entries: 71

Rep: Reputation: 65
procfs FTW!
i have a php-cgi server(website collecting and replying with few processes uptime info) that has system functions disabled, so i cannot extract process uptime/mem usage/etc from a direct shell command, which may even be slower than i do with reading procfs and parsing results. it's just great.

Last edited by Web31337; 12-10-2009 at 07:25 PM.
 
  


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
SleepAVG in /proc/[pid]/status aloktiagi Linux - Newbie 3 08-14-2009 08:02 AM
pmap or /proc/<pid>smap or /proc/<pid>/status iQoder Linux - Newbie 1 07-16-2009 07:32 PM
Is there any system function/api to get values like /proc/<pid>/status ??? kunalnandi Linux - Newbie 2 05-02-2009 02:22 AM
how to read /proc/pid/status in sched.c linuxdoniv Programming 3 07-21-2008 10:49 PM
VmSize : Regarding /proc/<pid>/status shivaligupta Programming 0 04-06-2006 05:33 AM


All times are GMT -5. The time now is 10:36 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration