title: get the process Memory Info in C
body: <p>I want to get the process memory Info in C. I am using Cygwin with GCC 4.5 on Windows XP. I include <code>#include &lt;psapi.h&gt;</code> and use <code>-lpsapi</code> when I build the program. 
  I get the error </p>
  
  <pre><code>undefined reference to _getprocessmemoryinfo@12
  </code></pre>
  
  <p>Please tell the correct way to get the Process Info of Memory in C. I read the <a href="https://stackoverflow.com/q/282194/1249810">this question</a>, but it is not helping with my problem.</p>
  
  <p>I use the code.</p>
  
  <pre><code>#include &lt;windows.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;psapi.h&gt;
  
  void PrintMemoryInfo( DWORD processID )
  {
      HANDLE hProcess;
      PROCESS_MEMORY_COUNTERS pmc;
  
      // Print the process identifier.
  
      printf( "\nProcess ID: %u\n", processID );
      getchar();
  
      // Print information about the memory usage of the process.
  
      hProcess = OpenProcess(  PROCESS_QUERY_INFORMATION |
                               PROCESS_VM_READ,
                               FALSE, 
                               processID );
      if (NULL == hProcess)
          return;
  
      if ( GetProcessMemoryInfo(hProcess, &amp;pmc, sizeof(pmc)) )
      {
          printf( "\tPageFaultCount: 0x%08X\n", pmc.PageFaultCount );
          printf( "\tYour app's PEAK MEMORY CONSUMPTION: 0x%08X\n", 
                    pmc.PeakWorkingSetSize );
          printf( "\tYour app's CURRENT MEMORY CONSUMPTION: 0x%08X\n", pmc.WorkingSetSize );
          printf( "\tQuotaPeakPagedPoolUsage: 0x%08X\n", 
                    pmc.QuotaPeakPagedPoolUsage );
          printf( "\tQuotaPagedPoolUsage: 0x%08X\n", 
                    pmc.QuotaPagedPoolUsage );
          printf( "\tQuotaPeakNonPagedPoolUsage: 0x%08X\n", 
                    pmc.QuotaPeakNonPagedPoolUsage );
          printf( "\tQuotaNonPagedPoolUsage: 0x%08X\n", 
                    pmc.QuotaNonPagedPoolUsage );
          printf( "\tPagefileUsage: 0x%08X\n", pmc.PagefileUsage ); 
          printf( "\tPeakPagefileUsage: 0x%08X\n", 
                    pmc.PeakPagefileUsage );
      }
  
      CloseHandle( hProcess );
  }
  
  int main( )
  {
    PrintMemoryInfo( GetCurrentProcessId() );
  
      return 0;
  }
  </code></pre>
  
  <p>Answers and suggestions are welcome.</p>