我如何才能得到整个主机的CPU和内存使用情况?API函数是什么?谢谢!

解决方案 »

  1.   

    VOID GetSystemInfo(
      LPSYSTEM_INFO lpSystemInfo  // system information
    );
      

  2.   

    GlobalMemoryStatusEx
    Example Code
    The following code shows a simple use of the GlobalMemoryStatusEx function.//  Sample output://  c:\>globalex
    //  78 percent of memory is in use.
    //  There are   65076 total Kbytes of physical memory.
    //  There are   14248 free Kbytes of physical memory.
    //  There are  150960 total Kbytes of paging file.
    //  There are   88360 free Kbytes of paging file.
    //  There are  1fff80 total Kbytes of virtual memory.
    //  There are  1fe770 free Kbytes of virtual memory.
    //  There are       0 free Kbytes of extended memory.#define _WIN32_WINNT 0x0500#include <windows.h>// Use to change the divisor from Kb to Mb.#define DIV 1024
    // #define DIV 1char *divisor = "K";
    // char *divisor = "";// Handle the width of the field in which to print numbers this way to
    // make changes easier. The asterisk in the print format specifier
    // "%*I64d" takes an int from the argument list, and uses it to pad 
    // and right-justify the number being formatted.
    #define WIDTH 7void main(int argc, char *argv[])
    {
      MEMORYSTATUSEX statex;  statex.dwLength = sizeof (statex);  GlobalMemoryStatusEx (&statex);  printf ("%ld percent of memory is in use.\n",
              statex.dwMemoryLoad);
      printf ("There are %*I64d total %sbytes of physical memory.\n",
              WIDTH, statex.ullTotalPhys/DIV, divisor);
      printf ("There are %*I64d free %sbytes of physical memory.\n",
              WIDTH, statex.ullAvailPhys/DIV, divisor);
      printf ("There are %*I64d total %sbytes of paging file.\n",
              WIDTH, statex.ullTotalPageFile/DIV, divisor);
      printf ("There are %*I64d free %sbytes of paging file.\n",
              WIDTH, statex.ullAvailPageFile/DIV, divisor);
      printf ("There are %*I64x total %sbytes of virtual memory.\n",
              WIDTH, statex.ullTotalVirtual/DIV, divisor);
      printf ("There are %*I64x free %sbytes of virtual memory.\n",
              WIDTH, statex.ullAvailVirtual/DIV, divisor);  // Show the amount of extended memory available.  printf ("There are %*I64x free %sbytes of extended memory.\n",
              WIDTH, statex.ullAvailExtendedVirtual/DIV, divisor);
    }from  MSDN