is there a way to execute system command with given priority?
-
12-06-2021 - |
Question
I mean this command:
system("myprogram.exe");
Is there a way to make it run for example in below-normal priority mode ?
La solution
The WINAPI has a function called CreateProcess()
that allows the specification of a priority:
dwCreationFlags [in] The flags that control the priority class and the creation of the process. For a list of values, see Process Creation Flags. This parameter also controls the new process's priority class, which is used to determine the scheduling priorities of the process's threads. For a list of values, see GetPriorityClass. If none of the priority class flags is specified, the priority class defaults to NORMAL_PRIORITY_CLASS unless the priority class of the creating process is IDLE_PRIORITY_CLASS or BELOW_NORMAL_PRIORITY_CLASS. In this case, the child process receives the default priority class of the calling process.
Autres conseils
You can use the SetThreadPriority() on the main thread of the application
I think this is a fuller answer:
Three different options (these aren't steps):
- During CreateProcess, specify the process priority CLASS (individual thread priorities are derived from the process priority class).
- After starting of the application, use SetPriorityClass. This lets you change the priority CLASS at will.
- Change individual thread priorities via SetThreadPriority. These go up and down in accordance with the 'base' priority CLASS.
For more information, see MSDN.
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow