LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > Solaris / OpenSolaris
User Name
Password
Solaris / OpenSolaris This forum is for the discussion of Solaris, OpenSolaris, OpenIndiana, and illumos.
General Sun, SunOS and Sparc related questions also go here. Any Solaris fork or distribution is welcome.

Notices


Reply
  Search this Thread
Old 03-22-2016, 04:11 AM   #1
dayalan_cse
Member
 
Registered: Oct 2006
Posts: 132

Rep: Reputation: 15
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
 
Old 03-22-2016, 04:41 AM   #2
cnamejj
Member
 
Registered: Mar 2015
Distribution: Ubuntu
Posts: 37

Rep: Reputation: Disabled
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.
 
Old 03-22-2016, 06:33 AM   #3
dayalan_cse
Member
 
Registered: Oct 2006
Posts: 132

Original Poster
Rep: Reputation: 15
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;

Last edited by dayalan_cse; 03-28-2016 at 07:58 AM.
 
Old 03-22-2016, 06:41 AM   #4
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Tribblix, Ubuntu/WSL
Posts: 9,761

Rep: Reputation: 459Reputation: 459Reputation: 459Reputation: 459Reputation: 459
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.

Last edited by jlliagre; 03-22-2016 at 06:42 AM.
 
Old 03-22-2016, 07:14 AM   #5
dayalan_cse
Member
 
Registered: Oct 2006
Posts: 132

Original Poster
Rep: Reputation: 15
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

Last edited by dayalan_cse; 03-28-2016 at 07:58 AM.
 
Old 03-22-2016, 08:52 AM   #6
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Tribblix, Ubuntu/WSL
Posts: 9,761

Rep: Reputation: 459Reputation: 459Reputation: 459Reputation: 459Reputation: 459
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.
 
Old 03-22-2016, 11:47 PM   #7
dayalan_cse
Member
 
Registered: Oct 2006
Posts: 132

Original Poster
Rep: Reputation: 15
Thank you Jlliagre, cnamejj and appreciated for your inputs.
 
Old 03-23-2016, 02:58 AM   #8
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Tribblix, Ubuntu/WSL
Posts: 9,761

Rep: Reputation: 459Reputation: 459Reputation: 459Reputation: 459Reputation: 459
You are welcome.

Again, please edit your previous postings to include code tags.
 
Old 03-28-2016, 08:00 AM   #9
dayalan_cse
Member
 
Registered: Oct 2006
Posts: 132

Original Poster
Rep: Reputation: 15
I have added code tags, thanks for letting me the steps to add the code tags.
 
  


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
/proc/$pid/status vs. system calls bozox Linux - Newbie 5 12-10-2009 06:24 PM
SleepAVG in /proc/[pid]/status aloktiagi Linux - Newbie 3 08-14-2009 07:02 AM
pmap or /proc/<pid>smap or /proc/<pid>/status iQoder Linux - Newbie 1 07-16-2009 06:32 PM
how to read /proc/pid/status in sched.c linuxdoniv Programming 3 07-21-2008 09:49 PM
VmSize : Regarding /proc/<pid>/status shivaligupta Programming 0 04-06-2006 04:33 AM

LinuxQuestions.org > Forums > Other *NIX Forums > Solaris / OpenSolaris

All times are GMT -5. The time now is 02:38 PM.

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