Platforms to show: All Mac Windows Linux Cross-Platform

Back to ProcessMBS class.

ProcessMBS.CurrentProcessID as Integer

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method Process MBS Util Plugin 10.4 ✅ Yes ✅ Yes ✅ Yes ❌ No Desktop, Console & Web
Returns the process ID of the application.
Example
MsgBox str(ProcessMBS.CurrentProcessID)

ProcessMBS.KillProcess(ProcessID as Integer, timeout as Integer) as Integer

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method Process MBS Util Plugin 10.3 ✅ Yes ✅ Yes ❌ No ❌ No Desktop, Console & Web
Kills a Process on Mac OS X or Windows.
Example
const pid = 12345 // put the PID here
call ProcessMBS.KillProcess pid, 100

Returns -1 if function is not available. Else returns a Mac OS error code where 0 equals "no error".

Returns on Windows:
0 - failed
1 - normal exit
2 - forced exit

The timeout is in milliseconds.
If you kill the main process of a task, this can kill the sub processes, too.

See also:

ProcessMBS.Priority(ProcessID as Integer) as Integer

Type Topic Plugin Version macOS Windows Linux iOS Targets
property Process MBS Util Plugin 12.1 ✅ Yes ❌ No ✅ Yes ❌ No Desktop, Console & Web
Sets or gets priority for a process on Mac and Linux.

Value is in the range -20 to 20. The default priority is 0; lower priorities cause more favorable scheduling.
For Windows, please use WinSetPriorityClass and WinGetPriorityClass.
(Read and Write computed property)

See also:

ProcessMBS.WinGetPriorityClass(ProcessID as Integer) as Integer

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method Process MBS Util Plugin 12.1 ❌ No ✅ Yes ❌ No ❌ No Desktop, Console & Web
Retrieves the priority class for the specified process.

You can pass ProcessID -1 to get the current process.
This value, together with the priority value of each thread of the process, determines each thread's base priority level.

If the function succeeds, the return value is the priority class of the specified process.

The process's priority class is one of the following values:
NameValueDescription
ABOVE_NORMAL_PRIORITY_CLASS&h00008000Process that has priority above NORMAL_PRIORITY_CLASS but below HIGH_PRIORITY_CLASS.
BELOW_NORMAL_PRIORITY_CLASS&h00004000Process that has priority above IDLE_PRIORITY_CLASS but below NORMAL_PRIORITY_CLASS.
HIGH_PRIORITY_CLASS&h00000080Process that performs time-critical tasks that must be executed immediately for it to run correctly. The threads of a high-priority class process preempt the threads of normal or idle priority class processes. An example is the Task List, which must respond quickly when called by the user, regardless of the load on the operating system. Use extreme care when using the high-priority class, because a high-priority class CPU-bound application can use nearly all available cycles.
IDLE_PRIORITY_CLASS&h00000040Process whose threads run only when the system is idle and are preempted by the threads of any process running in a higher priority class. An example is a screen saver. The idle priority class is inherited by child processes.
NORMAL_PRIORITY_CLASS&h00000020Process with no special scheduling needs.
REALTIME_PRIORITY_CLASS&h00000100Process that has the highest possible priority. The threads of a real-time priority class process preempt the threads of all other processes, including operating system processes performing important tasks. For example, a real-time process that executes for more than a very brief interval can cause disk caches not to flush or cause the mouse to be unresponsive.

Every thread has a base priority level determined by the thread's priority value and the priority class of its process. The operating system uses the base priority level of all executable threads to determine which thread gets the next slice of CPU time. Threads are scheduled in a round-robin fashion at each priority level, and only when there are no executable threads at a higher level will scheduling of threads at a lower level take place.
For a table that shows the base priority levels for each combination of priority class and thread priority value, see Scheduling Priorities.
Priority class is maintained by the executive, so all processes have a priority class that can be queried.

For Mac and Linux, please use Priority.

ProcessMBS.WinSetPriorityClass(ProcessID as Integer, PriorityClass as Integer) as Integer

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method Process MBS Util Plugin 12.1 ❌ No ✅ Yes ❌ No ❌ No Desktop, Console & Web
Sets the priority class for the specified process.

You can pass ProcessID -1 to get the current process.
This value together with the priority value of each thread of the process determines each thread's base priority level.

The process's priority class is one of the following values:
NameValueDescription
ABOVE_NORMAL_PRIORITY_CLASS&h00008000Process that has priority above NORMAL_PRIORITY_CLASS but below HIGH_PRIORITY_CLASS.
BELOW_NORMAL_PRIORITY_CLASS&h00004000Process that has priority above IDLE_PRIORITY_CLASS but below NORMAL_PRIORITY_CLASS.
HIGH_PRIORITY_CLASS&h00000080Process that performs time-critical tasks that must be executed immediately for it to run correctly. The threads of a high-priority class process preempt the threads of normal or idle priority class processes. An example is the Task List, which must respond quickly when called by the user, regardless of the load on the operating system. Use extreme care when using the high-priority class, because a high-priority class CPU-bound application can use nearly all available cycles.
IDLE_PRIORITY_CLASS&h00000040Process whose threads run only when the system is idle and are preempted by the threads of any process running in a higher priority class. An example is a screen saver. The idle priority class is inherited by child processes.
NORMAL_PRIORITY_CLASS&h00000020Process with no special scheduling needs.
REALTIME_PRIORITY_CLASS&h00000100Process that has the highest possible priority. The threads of a real-time priority class process preempt the threads of all other processes, including operating system processes performing important tasks. For example, a real-time process that executes for more than a very brief interval can cause disk caches not to flush or cause the mouse to be unresponsive.

Every thread has a base priority level determined by the thread's priority value and the priority class of its process. The operating system uses the base priority level of all executable threads to determine which thread gets the next slice of CPU time. Threads are scheduled in a round-robin fashion at each priority level, and only when there are no executable threads at a higher level will scheduling of threads at a lower level take place.
For a table that shows the base priority levels for each combination of priority class and thread priority value, see Scheduling Priorities.
Priority class is maintained by the executive, so all processes have a priority class that can be queried.

Every thread has a base priority level determined by the thread's priority value and the priority class of its process. The system uses the base priority level of all executable threads to determine which thread gets the next slice of CPU time. The SetThreadPriority function enables setting the base priority level of a thread relative to the priority class of its process. For more information, see Scheduling Priorities.
The *_PRIORITY_CLASS values affect the CPU scheduling priority of the process. For processes that perform background work such as file I/O, network I/O, or data processing, it is not sufficient to adjust the CPU scheduling priority; even an idle CPU priority process can easily interfere with system responsiveness when it uses the disk and memory. Processes that perform background work should use the PROCESS_MODE_BACKGROUND_BEGIN and PROCESS_MODE_BACKGROUND_END values to adjust their resource scheduling priorities; processes that interact with the user should not use PROCESS_MODE_BACKGROUND_BEGIN.
If a process is in background processing mode, the new threads it creates will also be in background processing mode. When a thread is in background processing mode, it should minimize sharing resources such as critical sections, heaps, and handles with other threads in the process, otherwise priority inversions can occur. If there are threads executing at high priority, a thread in background processing mode may not be scheduled promptly, but it will never be starved.
Each thread can enter background processing mode independently using SetThreadPriority. Do not call SetPriorityClass to enter background processing mode after a thread in the process has called SetThreadPriority to enter background processing mode. After a process ends background processing mode, it resets all threads in the process; however, it is not possible for the process to know which threads were already in background processing mode.

On any error the value is zero.
For Mac and Linux, please use Priority.

The items on this page are in the following plugins: MBS Util Plugin.


The biggest plugin in space...