LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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 05-01-2009, 04:32 AM   #1
kunalnandi
LQ Newbie
 
Registered: May 2009
Posts: 2

Rep: Reputation: 0
Question Is there any system function/api to get values like /proc/<pid>/status ???


Hello All,

I want memory log of my application and for that i want any system function that will give information similar to /proc/<My_App_Pid>/status.

basically i need all Virtual memory values like VmSize, VmPeak, VmRSS etc. and number of threads running.

Regards
Kunal Nandi
 
Old 05-01-2009, 09:16 PM   #2
tommylovell
Member
 
Registered: Nov 2005
Distribution: Fedora, Redhat
Posts: 372

Rep: Reputation: 101Reputation: 101
Nope. You don't need one. The proc filesystem is "in storage" and ascii, so a standard read of it is really efficient.
All of the utilities that I've ever seen that access the proc filesystem use standard open/read/close.

Here's a function that'll work.

Code:
static int read_proc_file(char *file_name, char *buffer, int size)
{
        int num_bytes_read, fp;

        fp = open(file_name, O_RDONLY);
        if (!fp) {
                syslog(LOG_ERR, "Failed to open %s: %s\n", file_name,
                        strerror(errno));
                return -1;
        }

        num_bytes_read = read(fp, buffer, size);
        if (num_bytes_read < 0) {
                syslog(LOG_ERR, "Failed to read %s\n", file_name);
                close(fp);
                return -1;
        }

        close(fp);
        return num_bytes_read;
}
 
Old 05-02-2009, 01:22 AM   #3
kunalnandi
LQ Newbie
 
Registered: May 2009
Posts: 2

Original Poster
Rep: Reputation: 0
Smile

actually i hv already tried this before but, i was looking for some system function any ways thanks for your reply

Quote:
Originally Posted by tommylovell View Post
Nope. You don't need one. The proc filesystem is "in storage" and ascii, so a standard read of it is really efficient.
All of the utilities that I've ever seen that access the proc filesystem use standard open/read/close.

Here's a function that'll work.

Code:
static int read_proc_file(char *file_name, char *buffer, int size)
{
        int num_bytes_read, fp;

        fp = open(file_name, O_RDONLY);
        if (!fp) {
                syslog(LOG_ERR, "Failed to open %s: %s\n", file_name,
                        strerror(errno));
                return -1;
        }

        num_bytes_read = read(fp, buffer, size);
        if (num_bytes_read < 0) {
                syslog(LOG_ERR, "Failed to read %s\n", file_name);
                close(fp);
                return -1;
        }

        close(fp);
        return num_bytes_read;
}
Regards
Kunal Nandi
 
  


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
uid and gid fileds from /proc/pid/status sanjaykhuntia Linux - Enterprise 2 02-11-2011 01:35 PM
/proc/pid/status , is the data related to all the threads of the process...... linuxdoniv Programming 2 08-06-2008 11:51 PM
how to read /proc/pid/status in sched.c linuxdoniv Programming 3 07-21-2008 09:49 PM
/proc/pid/io seems not to work kornelix Linux - Server 5 06-17-2007 02:39 AM
VmSize : Regarding /proc/<pid>/status shivaligupta Programming 0 04-06-2006 04:33 AM


All times are GMT -5. The time now is 11:16 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration