将过程亲和力设置为特定过程
Setting process affinity to a specific process
我想将过程亲和力设置为特定过程。
喜欢:我有一个称为" word.exe"的过程:2045我如何设置流程亲和力?
我在网上搜索,但找不到太多。我只找到了getCurrentProcess((,但它仅设置了当前过程的过程亲和力。
int main()
{
DWORD processID = GetCurrentProcessId();
HANDLE process = GetCurrentProcess();
DWORD_PTR processAffinityMask = 1;
BOOL success = SetProcessAffinityMask(process, processAffinityMask);
SetPriorityClass(GetCurrentProcess(), THREAD_PRIORITY_TIME_CRITICAL);
cout << success << " " << processID << endl; //returns 1 if everything goes okay
}
编辑我的意思是:有一个替代getCurrentProcess((的替代品,而不是设置与当前过程的亲和力,而是将亲和力设置为我想要的特定过程?
我可以使用另一个功能更改GetCurrentProcces((吗? 是的。
#include <iostream>
#include <windows.h>
#include <tlhelp32.h>
HANDLE GetProcessHandleByName(const std::wstring& processName)
{
HANDLE hProcess = NULL;
PROCESSENTRY32 processInfo;
processInfo.dwSize = sizeof(processInfo);
HANDLE processesSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
if (processesSnapshot == INVALID_HANDLE_VALUE) {
return 0;
}
Process32First(processesSnapshot, &processInfo);
if (!processName.compare(processInfo.szExeFile))
{
CloseHandle(processesSnapshot);
hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, processInfo.th32ProcessID);
return hProcess;
}
while (Process32Next(processesSnapshot, &processInfo))
{
if (!processName.compare(processInfo.szExeFile))
{
CloseHandle(processesSnapshot);
hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, processInfo.th32ProcessID);
return hProcess;
}
}
CloseHandle(processesSnapshot);
return hProcess;
}
用法:
HANDLE hProcess = GetProcessHandleByName(L"word.exe");
btw:在SetPriorityClass
中,dwPriorityClass
中没有参数THREAD_PRIORITY_TIME_CRITICAL
,也许您要使用SetThreadPriority
。
相关文章:
- 为不同配置设置MSVC_RUNTIME_LIBRARY的正确方法是什么
- 在C++/Linux中设置单调时钟的一些技巧
- 递归函数计算序列中的平方和(并输出过程)
- 如何在选项卡视图Qt中设置一个新项目,并保存以前的项目
- 嵌套在类中时无法设置成员数据
- 需要帮助设置在C++中使用的Potrace
- 如何在自删除后将对象设置为nullptr
- 将指针设置为"nullptr"并不能防止双重删除?
- 如何在Ubuntu中使用cmake设置qt4
- ld:bind_at_load和-bitcode_bundle(Xcode设置ENABLE_bitcode=YES)不能
- Vulkan:为什么主命令缓冲区和辅助命令缓冲区都需要设置帧缓冲区和渲染过程
- 在底部设置运行过程
- 将过程亲和力设置为特定过程
- 如何设置背景过程名称
- 我可以编程设置ENV使用BAT,然后发出一个过程
- 为特定过程的特定运行设置环境变量
- 在 OpenGL 中设置 VAO 的过程
- 如何设置Visual C++2010学习版以在生成过程中复制某些文件夹
- BoostSpirit:在解析过程中设置子语法
- 在定义过程中将std::string设置为0与将std::字符串设置为0相比