title: Is there something wrong with my linux code to check memory usage?
body: <p>I have a question about code below.<br />
  Is curMemoryInfo.phyMem the current process's RAM memory usage?</p>
  <p>I'm having a Memory Leak and it's only happening on Linux.<br />
  I am checking the memory leak with the code below on Linux and<br />
  using the Visual Studio debugger on Windows.</p>
  <p>Is there something wrong with my code to check for memory leaks in Linux?</p>
  <pre class="lang-cpp prettyprint-override"><code>FILE* file;
  char processStatPath[128] = { 0, };
  
  sprintf( processStatPath, &quot;/proc/%d/statm&quot;, inputPId );
  
  file = fopen( processStatPath, &quot;r&quot; );
  
  if( !file )
  {
      //NV_TRACE_MSG(TRUE, &quot;PID:%d Not available!!!&quot;, inputPId) ;
      return false;
  }
  
  unsigned long size = -1; // VmSize
  unsigned long resident = -1; // VmRSS
  unsigned long share = -1; // shared
  unsigned long text = -1; // text size
  unsigned long lib = -1; // lib size
  unsigned long data = -1; // VmData + VmStk
  unsigned long dt = -1; // dirty page
  
  int ret = fscanf( file, &quot;%lu %lu %lu %lu %lu %lu %lu&quot;,
                    &amp;size,
                    &amp;resident,
                    &amp;share,
                    &amp;text,
                    &amp;lib,
                    &amp;data,
                    &amp;dt );
  
  fclose( file );
  
  curMemoryInfo.phyMem = ( resident - share )*pageSize; // non swap memory (physical memory)
  curMemoryInfo.wholeMem = ( size - share )*pageSize; // whole memory (swap + physical memory)
  curMemoryInfo.sharedMem = share * pageSize;// shared memory
  ...
  ...
  // compare wiht prev_memory_usage
  ...
  ...
  </code></pre>