Код: Выделить всё
while (TRUE) {
status = NtQuerySystemInformation(SystemProcessInformation, buffer, len, &returnLength);
if (status == STATUS_INFO_LENGTH_MISMATCH) {
len = returnLength;
buffer = realloc(buffer, len);
} else if (NT_SUCCESS(status)) {
break;
} else {
printf("Error querying system information\n");
free(buffer);
return;
}
}
SYSTEM_PROCESS_INFORMATION *processInfo = (SYSTEM_PROCESS_INFORMATION *)buffer;
// We will use an array of sets to store PIDs for each core
SYSTEM_INFO systemInfo;
GetSystemInfo(&systemInfo);
const int NUM_CORES = systemInfo.dwNumberOfProcessors;
std::set corePids[NUM_CORES]; // array of sets to store unique PIDs for each core
while (processInfo) {
for (ULONG i = 0; i < processInfo->NumberOfThreads; i++) {
SYSTEM_THREAD_INFORMATION *threadInfo = &processInfo->Threads[i];
DWORD_PTR affinityMask = 0;
HANDLE threadHandle;
OBJECT_ATTRIBUTES attrs = {0};
InitializeObjectAttributes(&attrs, NULL, 0, 0, 0);
NTSTATUS openThreadStatus = NtOpenThread(&threadHandle, THREAD_QUERY_INFORMATION, &attrs, &threadInfo->ClientId);
if (!NT_SUCCESS(openThreadStatus)){
DWORD e = GetLastError();
if (e == 5){
printf("Could not open thread: Access Denied\n");
continue;
} else {
printf("Could not open thread %u...os %u\n", e, openThreadStatus);
continue;
}
}
if (threadHandle != NULL) {
if (GetThreadAffinityMask(threadHandle, &affinityMask)) {
// Iterate through each bit of the affinity mask and assign the thread to the corresponding core
for (unsigned int core = 0; core < sizeof(affinityMask) * 8; core++) {
if (affinityMask & (1 ClientId.UniqueThread, GetProcessId(processInfo), GetLastError());
}
}
if (processInfo->NextEntryOffset == 0) {
break;
}
processInfo = (SYSTEM_PROCESS_INFORMATION *)((char *)processInfo + processInfo->NextEntryOffset);
}
Код: Выделить всё
Could not open thread 0...os 3221225506Подробнее здесь: https://stackoverflow.com/questions/793 ... on-windows
Мобильная версия