Memory sorting is actually very simple. You can use emptyworkingset to use this function for each process.
The Code is as follows:
# Include <windows. h>
# Include <stdio. h>
# Include <tlhelp32.h>
# Include <psapi. h>
# Pragma comment (Lib, "psapi. lib ")
Bool test ()
{
Handle snapshot = createconlhelp32snapshot (th32cs_snapprocess, 0 );
If (snapshot = NULL)
{
Return false;
}
Processentry32 processinfo; // declare the process information variable
Processinfo. dwsize = sizeof (processinfo); // you can specify the processinfo size.
// Return the information of the first PROCESS IN THE SYSTEM
Bool status = process32first (snapshot, & processinfo );
While (Status)
{
Handle hprocess = OpenProcess (process_all_access, true, processinfo. th32processid );
If (hprocess)
{
Setprocessworkingsetsize (hprocess, 0, 0 );
// Memory sorting
Emptyworkingset (hprocess );
Closehandle (hprocess );
}
Printf ("% s/n", processinfo. szexefile );
// Obtain information about the next process
Status = process32next (snapshot, & processinfo );
}
Return true;
}
Int main ()
{
Test ();
Return 0;
}