Hi all,
I tried to output memory usage information while the process is
executing at a particular time. I found out some people
suggesting calling the ioctl. I followed it and wrote a test example:
#include <unistd.h>
#include <stdlib.h>
#include <iostream.h>
#include <fcntl.h>
#include <sys/procfs.h>
int main(int * argc, char ** argv)
{
pid_t pid = getpid();
char fname[100];
sprintf(fname, "/proc/%ld", pid);
int fd;
fd=open(fname, O_RDONLY);
prpsinfo_t ps_info;
ioctl\(fd, PIOCPSINFO, &ps_info\);
cout << "pid:" << pid << " init memory:" << ps\_info.pr_bysize << endl;
char ** pString;
//char * pInteger[128];
pString = new char * [128];
for\(int k = 0; k < 128 ; k\+\+\)
\{
char *p = new char [1024 * 1024];
pString[k] = p;
}
ioctl\(fd, PIOCPSINFO, &ps_info\);
cout << "pid:" << pid << " after memory:" << ps\_info.pr_bysize <<
endl;
close\(fd\);
for\(int k = 0; k < 128; k\+\+\)
delete []\(pString[k]\);
delete []pString;
}
And compiled it with Sun CC on solaris5.8. I thought the second output
must be more than 128M. But the real one is : memory:0. Have I misused
ioctl or something else?
Best Regards,
Lan Chen