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
How to monitor the IBM AIX server for I/O usage,memory usage,CPU usage,network..? laknar AIX 3 07-16-2009 05:35 AM
Memory usage in Solaris - memory not freed? gewurtz SUN Solaris 3 01-06-2009 12:06 PM
current CPU usage, memory usage, disk I/O oid(snmp) S_venkatesh SUN Solaris 2 12-13-2008 06:19 AM
how can I find cpu usage memory usage swap usage and logical volume usage alert0919 HP-UX 3 12-02-2008 02:38 PM
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

Reply
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 2 Weeks Ago
nagalenoj nagalenoj is offline
Registered User
  
 

Join Date: Aug 2007
Location: chennai
Posts: 27
Thumbs up Memory usage

Hi.,
I want to know amount of memory used by a process inside the same process. For example, I am writing a program and I want to know the memory used by it from the program. So, I could do some actions (flush some unwanted data structures/ log the memory usage) in my program based on this value. I don't like to parse the top command's output.
I know this value will be stored in /proc directory. I've referred the /proc/<pid>/statm, status, stat files. But, I'm unable to find how top command is calculating that a process is utilizing x% of memory.
  #2 (permalink)  
Old 2 Weeks Ago
pogdorica's Avatar
pogdorica pogdorica is offline
Registered User
  
 

Join Date: Oct 2009
Location: Madrid
Posts: 53
Hi.
I have a C program that it does:

Code:
   sprintf (fichero, "/proc/%d/statm", getpid ());
   fd = open (fichero, O_RDONLY);
   nbytes = read (fd, mem_info, sizeof (mem_info) - 1);
   close (fd);
   mem_info[nbytes] = '\0';
   nbytes = sscanf (mem_info, "%*d %d", &rss);
   printf ( "Memory: %dKb.\n",  rss * getpagesize() / 1024);

   ==> Memory: xxxx Kb.
  #3 (permalink)  
Old 2 Weeks Ago
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,717
You can also call getrusage().
Reply

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 11:33 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