LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   /proc/$pid/status vs. system calls (https://www.linuxquestions.org/questions/linux-newbie-8/proc-%24pid-status-vs-system-calls-774512/)

bozox 12-09-2009 11:19 AM

/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...

malekmustaq 12-09-2009 12:39 PM

bosox,

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

or try --$ top

syg00 12-09-2009 04:44 PM

No idea - why not read /proc/<pid>/status directly ?.

bozox 12-10-2009 09:05 AM

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.

syg00 12-10-2009 04:21 PM

/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".

Web31337 12-10-2009 06:24 PM

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.


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