LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Is there any system function/api to get values like /proc/<pid>/status ??? (https://www.linuxquestions.org/questions/linux-newbie-8/is-there-any-system-function-api-to-get-values-like-proc-pid-status-722886/)

kunalnandi 05-01-2009 04:32 AM

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

tommylovell 05-01-2009 09:16 PM

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;
}


kunalnandi 05-02-2009 01:22 AM

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 (Post 3527371)
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


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