![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| cpu, memory and virtual memory usage | ocelot | UNIX for Dummies Questions & Answers | 4 | 12-01-2008 07:57 AM |
| How can I get memory usage or anything that show memory used from sar file? | panithat | HP-UX | 1 | 03-31-2008 12:26 PM |
| CPU usage and memory usage | mansoorulhaq | High Level Programming | 1 | 08-09-2007 04:55 PM |
| Monitor CPU usage and Memory Usage | Gajanad Bihani | High Level Programming | 2 | 03-09-2005 07:35 AM |
| Memory usage | vslewis | HP-UX | 2 | 12-16-2004 04:37 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
how to use ioctl to check out memory usage
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 |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|