我想为子进程设置优先级,但是SetInformationJobObject函数有1314错误代码。那么如何解决这个问题?
#include <windows.h>
#include <iostream>
using namespace std;
int main() {
JOBOBJECT_BASIC_LIMIT_INFORMATION limits;
limits.LimitFlags = JOB_OBJECT_LIMIT_PRIORITY_CLASS;
limits.PriorityClass = HIGH_PRIORITY_CLASS;
HANDLE Job = CreateJobObject(NULL, NULL);
SetInformationJobObject(Job, JobObjectBasicLimitInformation, &limits, sizeof(limits));
cout << GetLastError() << endl;
AssignProcessToJobObject(Job, GetCurrentProcess());
STARTUPINFO cif;
ZeroMemory(&cif, sizeof(STARTUPINFO));
cif.cb = sizeof(STARTUPINFO);
PROCESS_INFORMATION pi;
CreateProcess("sp.exe", NULL, NULL, NULL, FALSE, 0, NULL, NULL, &cif, &pi);
cout << "Child process priority = " << GetPriorityClass(pi.hProcess);
CloseHandle(Job);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
}
GetPriorityClass必须返回128,但返回32。