The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-31-2006
lanchen lanchen is offline
Registered User
  
 

Join Date: Jan 2006
Posts: 3
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
  #2 (permalink)  
Old 01-31-2006
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,717
I don't know what you're doing - but getrusage() is the standard way to get cpu usage - usually in ms.
  #3 (permalink)  
Old 01-31-2006
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
I got:
143> /opt/SUNWspro/bin/CC proc.c -o proc
144> ./proc
pid:15832 init memory:1208320
pid:15832 after memory:135426048

Try opening "/proc/self" which is how everyone else does it. But getting your own pid should work too. Check the error codes after each system call. That will give you a clue.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:07 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0