ioctl using PIOCPSINFO not reporting proper virtual memory
Hi,
I am trying to get the virtual memory usage on Solaris 8 and 10 machines using ioctl function, ioctl(fd,PIOCPSINFO,&p_buffer)
Before calling the function, I allocate memory of 1 GB for a character pointer.
Then I call the ioctl function check the value of p_buffer.pr_bysize.
Then I free the memory allocated to that pointer and once again call ioctl function and check the value of buffer.pr_bysize.
I do this memory allocation and freeing 10 times. But virtual memory usage is not changing at all.
Following is the code segment I am using and following that I have pasted the output. Please let me know what is wrong with the program. I am running this on solaris 10. I found the same behaviour on solaris 8 as well.
unsigned int getvmsize()
{
int fd;
pid_t pid = getpid();
char filename[50];
sprintf(filename,"/proc/self");
if ((fd=open(filename,O_RDONLY)) == -1)
{
cout << "Opening file " << filename << " failed " << endl;
return(0);
}
prpsinfo_t p_buffer;
if (ioctl(fd,PIOCPSINFO,&p_buffer) != -1)
{
close(fd);
return (p_buffer.pr_bysize);
}
else
{
close(fd);
cout << "ioctl for PIOCPSINFO failed " << endl;
return(0);
}
}
int main(int argc, char **argv)
{
unsigned counter=1 ;
unsigned long vmsize;
while (counter++ < 10)
{
vmsize = getvmsize();
char chararray = (char) malloc(1024 * 1024 * 1024);
vmsize = getvmsize();
cout << "VM SIZE BEFORE FREE = " << vmsize << endl;
free (chararray);
vmsize = getvmsize();
cout << "VM SIZE AFTER FREE = " << vmsize << endl;
cout << "**************************************************************" << endl;
}
vmsize = getvmsize();
return(0);
}
Following is the output I am getting:
VM SIZE BEFORE FREE = 2449408
VM SIZE AFTER FREE = 2449408
**************************************************************
VM SIZE BEFORE FREE = 2449408
VM SIZE AFTER FREE = 2449408
**************************************************************
VM SIZE BEFORE FREE = 2449408
VM SIZE AFTER FREE = 2449408
**************************************************************
VM SIZE BEFORE FREE = 2449408
VM SIZE AFTER FREE = 2449408
**************************************************************
VM SIZE BEFORE FREE = 2449408
VM SIZE AFTER FREE = 2449408
**************************************************************
and so on........
thanks
waavman