Thread: Getting VmSize of a running process

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    4

    Getting VmSize of a running process

    Hi all,

    I'd be glad of any help with either or both of the following questions:

    1. What would be the preferred (or most efficient) way of getting an application's current VmSize programatically?

    2. Assuming (as I suspect) that the best way to get the above data is from /proc/<pid>/status, can anybody point me to the best way to parse this file?

    Essentially what I would need to do in that case is the C equivalent of the following:

    grep -i vmsize /proc/<pid>/status | awk '{print $2}'

    Thanks in anticipation,

    Ruairi

  2. #2
    Registered User
    Join Date
    Mar 2003
    Posts
    4
    Thanks very much for that. Here's exactly what worked in the end.

    Code:
            FILE *fp;
            int myint;
            int BUFFERSIZE=80;
            char *buf=malloc(85);
            if((fp = fopen("/proc/1/status","r"))){
                    while(fgets(buf, BUFFERSIZE, fp) != NULL){
                            if(strstr(buf, "VmSize") != NULL){
                                    if (sscanf(buf, "%*s %d", &myint) == 1){
                                            printf("VmSize is %d\n", myint);
                                    }
                            }
                    }
            }
    Now for some cleanup, and integration into the project

    Ruairķ

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A few process questions...
    By DavidG in forum C Programming
    Replies: 5
    Last Post: 05-11-2006, 09:06 AM
  2. Retrieving binary file name from a process
    By maxhavoc in forum Linux Programming
    Replies: 5
    Last Post: 04-12-2006, 02:50 PM
  3. process ring
    By gregulator in forum C++ Programming
    Replies: 0
    Last Post: 02-28-2005, 08:21 PM
  4. binary tree of processes
    By gregulator in forum C Programming
    Replies: 1
    Last Post: 02-28-2005, 12:59 AM
  5. Application running as a process in Win2k?????
    By J_Bravo in forum Windows Programming
    Replies: 8
    Last Post: 05-07-2002, 04:02 AM