Finding SC_PAGE_SIZE using Python on Windows

I work in this mixed environment, where I am on a Windows machine, using Simics and Cygwin to run some code in an environment like unix. I was coding in C, but I'm interested in trying to execute my solution in Python. In a unix environment, to search for SC_PAGE_SIZE you can simply:

 #Python-2.7, unix environment page_size = os.sysconf("SC_PAGE_SIZE") 

If you code c, you can do:

 #C, unix environment size_t page_size = (size_t) sysconf (_SC_PAGESIZE); 

However, when using python on Windows, os.sysconf does not exist, and I could not find a replacement. What can I use in python to find the PAGE_SIZE environment.

Side note. I know that you may wonder why I use the installation as it is, and this is not my choice. This is homework from work. The question I ask is not for homework for my own benefit.

+4
source share
4 answers

Try:

 import mmap print mmap.PAGESIZE 
+8
source

I am not an expert on the system, so I am not doing what corresponds to SC_PAGE_SIZE on windows. Hovever, you can use WMI to query system performance.

Here is an example that should give a lot of things. You can find what you are looking for:

 import win32com.client import unicodedata def _(text): if type(text) is unicode: return unicodedata.normalize('NFKD', text).encode('ascii','ignore') return text def to_kb(x): if x: return int(x)/1024 return x strComputer = "." objWMIService = win32com.client.Dispatch("WbemScripting.SWbemLocator") objSWbemServices = objWMIService.ConnectServer(strComputer,"root\cimv2") colItems = objSWbemServices.ExecQuery("Select * from Win32_Process") for objItem in colItems: print "------------------------------------------" print "Command Line: ", _(objItem.CommandLine) print "Process Id: ", objItem.ProcessId print "Handle: ", objItem.Handle print "Handle Count: ", objItem.HandleCount print "Maximum Working Set Size: ", to_kb(objItem.MaximumWorkingSetSize) print "Minimum Working Set Size: ", to_kb(objItem.MinimumWorkingSetSize) print "Page Faults: ", objItem.PageFaults print "PageFile Usage: ", objItem.PageFileUsage print "Peak PageFile Usage: ", objItem.PeakPageFileUsage print "Peak Virtual Size: ", objItem.PeakVirtualSize print "Peak Working Set Size: ", objItem.PeakWorkingSetSize print "Private Page Count: ", objItem.PrivatePageCount print "Quota NonPaged Pool Usage: ", objItem.QuotaNonPagedPoolUsage print "Quota Paged Pool Usage: ", objItem.QuotaPagedPoolUsage print "Quota Peak NonPaged Pool Usage: ", objItem.QuotaPeakNonPagedPoolUsage print "Quota Peak Paged Pool Usage: ", objItem.QuotaPeakPagedPoolUsage print "Virtual Size: ", objItem.VirtualSize print "Working Set Size: ", to_kb(objItem.WorkingSetSize) print "Write Operation Count: ", objItem.WriteOperationCount print "Write Transfer Count: ", objItem.WriteTransferCount 
+1
source

The only equivalent I could find was in C, but if I compile the code and then execute it from python, I can get the result I was looking for. Unfortunately, at the moment there is no python command that runs on Windows that is as simple as the unix version, but that at least gives me the result.

 int main(void) { SYSTEM_INFO si; GetSystemInfo(&si); printf("%u", si.dwPageSize); return 0; } 
+1
source

This can be done using the ctypes module:

 from ctypes import Structure, byref, windll from ctypes.wintypes import WORD, DWORD, LPVOID class SYSTEM_INFO(Structure): _fields_ = [ ("wProcessorArchitecture", WORD), ("wReserved", WORD), ("dwPageSize", DWORD), ("lpMinimumApplicationAddress", LPVOID), ("lpMaximumApplicationAddress", LPVOID), ("dwActiveProcessorMask", DWORD), ("dwNumberOfProcessors", DWORD), ("dwProcessorType", DWORD), ("dwAllocationGranularity", DWORD), ("wProcessorLevel", WORD), ("wProcessorRevision", WORD), ] si = SYSTEM_INFO() windll.kernel32.GetSystemInfo(byref(si)) print(si.dwPageSize) 
0
source

Source: https://habr.com/ru/post/1390718/


All Articles