日期:2014-05-17  浏览次数:21595 次

各位大虾,怎么获取windows系统的核心内存的分页数与未分页数…急啊……
怎样用java或py脚本、C、C++获取windows系统的核心内存的分页数与未分页数……请各位大虾们指点指点,这个任务很急……
  打开任务管理器--》性能--》核心内存中分页数与未分页数

------解决方案--------------------
沙发
jf
坐等大牛出现
------解决方案--------------------
估计得内核函数才能取到。
------解决方案--------------------
GlobalMemoryStatusEx

查了MSDN,下面的函数获取

The GlobalMemoryStatusEx function obtains information about the system's current usage of both physical and virtual memory.


BOOL GlobalMemoryStatusEx(
LPMEMORYSTATUSEX lpBuffer
);
Parameters
lpBuffer 
[in, out] Pointer to a MEMORYSTATUSEX structure that receives information about current memory availability. 
Return Values
If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks
You can use the GlobalMemoryStatusEx function to determine how much memory your application can allocate without severely impacting other applications.

The information returned by the GlobalMemoryStatusEx function is volatile. There is no guarantee that two sequential calls to this function will return the same information.

Example Code [C++]
The following code shows a simple use of the GlobalMemoryStatusEx function.

// Sample output:
// 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 1

char *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 7

void 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);
}