LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Solaris / OpenSolaris (https://www.linuxquestions.org/questions/solaris-opensolaris-20/)
-   -   VmSize in /proc/<pid>/status (https://www.linuxquestions.org/questions/solaris-opensolaris-20/vmsize-in-proc-pid-status-4175575578/)

dayalan_cse 03-22-2016 04:11 AM

VmSize in /proc/<pid>/status
 
Hi All,

Linux:
-------

To get 'VmSize' in Linux, i was trying to read file /proc/<pid>/status and search for 'VmSize' to identify the VmSize of the process.

How to get VmSize in Solaris 5.10 platform?

I opened /proc/$$/status but it looks like this file is non-readable (not in ascii format).

How to get VmSize from path /proc/<pid>/... in Solari platform?

Thanks

cnamejj 03-22-2016 04:41 AM

The "/proc" files on Solaris are not text file so you just can "cat" them and pull out the fields you want. It's been a very, very long time since I wrote Solaris code that read "/proc" data but it's pretty straightforward as long as you're programming in C.

You just have to read the man pages to figure out what structure goes with the "/proc" file (or files) that have the data you're interested in. But in the end, once you have the structure identified getting data from "/proc" files is simpler on Solaris than Linux, since it's parse into fields automatically.

dayalan_cse 03-22-2016 06:33 AM

Thanks.

in Linux: /proc/PID/status - the field name is 'VmSize'

in Solaris: I found there is pstatus_t structure, in the below structure which field indicates the virtual memory size (in other words, equal field name of Linux VmSize value).


Code:

typedef struct pstatus {
    int pr_flags;            /* flags (see below) */
    int pr_nlwp;              /* number of active lwps in the process */
    int pr_nzomb;            /* number of zombie lwps in the process */
    pid_tpr_pid;              /* process id */
    pid_tpr_ppid;            /* parent process id */
    pid_tpr_pgid;            /* process group id */
    pid_tpr_sid;              /* session id */
    id_t pr_aslwpid;          /* obsolete */
    id_t pr_agentid;          /* lwp-id of the agent lwp, if any */
    sigset_t pr_sigpend;      /* set of process pending signals */
    uintptr_t pr_brkbase;    /* virtual address of the process heap */
    size_t pr_brksize;        /* size of the process heap, in bytes */
    uintptr_t pr_stkbase;    /* virtual address of the process stack */
    size_tpr_stksize;        /* size of the process stack, in bytes */
    timestruc_t pr_utime;    /* process user cpu time */
    timestruc_t pr_stime;    /* process system cpu time */
    timestruc_t pr_cutime;    /* sum of children's user times */
    timestruc_t pr_cstime;    /* sum of children's system times */
    sigset_t pr_sigtrace;    /* set of traced signals */
    fltset_t pr_flttrace;    /* set of traced faults */
    sysset_t pr_sysentry;    /* set of system calls traced on entry */
    sysset_t pr_sysexit;      /* set of system calls traced on exit */
    char pr_dmodel;          /* data model of the process */
    taskid_t pr_taskid;      /* task id */
    projid_t pr_projid;      /* project id */
    zoneid_t pr_zoneid;      /* zone id */
    lwpstatus_t pr_lwp;      /* status of the representative lwp */
} pstatus_t;


jlliagre 03-22-2016 06:41 AM

This small C code will read the virtual size of a process when getting its input from /proc/<pid>/psinfo file (not the /proc/<pid>/status one):

Code:

#include <stdio.h>
#include <procfs.h>

main() {
        psinfo_t psinfo;
        read(0,&psinfo,sizeof(psinfo_t));
        printf("%lld\n",psinfo.pr_size*1024/getpagesize());
}

Note: it must be compiled in 64 bit.

dayalan_cse 03-22-2016 07:14 AM

Thanks.

Do we need divide using getpagesize() function returned value? can you please confirm.

Code:

ps -opid,ppid,vsz -u <userid> | grep 14390
output:
--------
14390 13286 1568

vm size seems to be 1568.


Code:

#include <stdio.h>
#include <unistd.h>
#include <procfs.h>

int main(void)
{

 unsigned int pid;
 FILE *file;
 psinfo_t psinfo;
 char psinfopath[1024];

 sprintf(psinfopath, "/proc/%d/psinfo", pid);

 file = fopen(psinfopath, "r");

 if( file == NULL ) {
  printf("Unable to open file\n");
  exit(1);
 }

 fread( &psinfo, sizeof(psinfo_t), 1, file);
 printf("pr_size: %d\n", psinfo.pr_size);
 printf(" vm size: %d\n", (psinfo.pr_size*1024)/pagesize);
 getchar();

}

Output:
----------
pr_size: 1568
vm size: 196

jlliagre 03-22-2016 08:52 AM

You can simplify your test command with:

Code:

ps -opid,ppid,vsz -p 14390
You are anyway right, the field is documented to represent the size in kilobytes so there is no need to divide it:

Code:

  size_t  pr_size;  /* size of process image in Kbytes */
PS: Please edit your previous postings to include code tags.

dayalan_cse 03-22-2016 11:47 PM

Thank you Jlliagre, cnamejj and appreciated for your inputs.

jlliagre 03-23-2016 02:58 AM

You are welcome.

Again, please edit your previous postings to include code tags.

dayalan_cse 03-28-2016 08:00 AM

I have added code tags, thanks for letting me the steps to add the code tags.


All times are GMT -5. The time now is 08:48 PM.