Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version
long rss = 0L;
FILE* fp = NULL;
if ( (fp = fopen( "/proc/self/statm", "r" )) == NULL )
    cout << "cant open \n";     /* Can't open? */
if ( fscanf( fp, "%*s%ld", &rss ) != 1 )
{
   fclose( fp );
   cout << "cant read \n";      /* Can't read? */
}
fclose( fp );
cout << (size_t)rss  << "\n";

Found this way to measure the memory usage. This seems to work better than the ru_maxrss.

long rss = 0L;
FILE* fp = NULL;
if ( (fp = fopen( "/proc/self/statm", "r" )) == NULL )
    cout << "cant open \n";     /* Can't open? */
if ( fscanf( fp, "%*s%ld", &rss ) != 1 )
{
   fclose( fp );
   cout << "cant read \n";      /* Can't read? */
}
fclose( fp );
cout << (size_t)rss  << "\n";

Found this way to measure the memory usage. This seems to work better than the ru_maxrss.ru_maxrss. At least it shows a more constant usage.

long rss = 0L;
FILE* fp = NULL;
if ( (fp = fopen( "/proc/self/statm", "r" )) == NULL )
    cout << "cant open \n";     /* Can't open? */
if ( fscanf( fp, "%*s%ld", &rss ) != 1 )
{
   fclose( fp );
   cout << "cant read \n";      /* Can't read? */
}
fclose( fp );
cout << (size_t)rss  << "\n";

Found this way to measure the memory usage. This seems to work better than the ru_maxrss. At least it shows a more constant usage.usage and most likely this is also the current usage and not maxrss.