All Caché programs and applications are run by a process. A process is identified by a system-generated integer process ID (referred to as a pid).
A process can be either a foreground (interactive) process, or a background (non-interactive) process. A background process is initiated in ObjectScript using the JOB command. The process issuing the JOB command is known as the parent process, the initiated background process is known as the child process. A background process may also be referred to as a “jobbed process” or a “spawned process”.
Processes hold and release shared resources using locks. In ObjectScript a process acquires and releases locks using the LOCK command. To view the current locks, refer to the system-wide lock table, described in the “Lock Management” chapter of Using Caché ObjectScript.
This chapter describes the following aspects of process management:
For other aspects of process management, refer to the %SYS.ProcessQuery class.
Caché provides optimal defaults for all aspects of process management. Changing these process defaults should be done with caution, and only for specific special circumstances.
A process executes either in the default mode, sometimes referred to as Interactive Mode (this is unrelated to user interaction), or in Batch Mode. Batch Mode should be used only for special and extreme circumstances.
A process that will access large portions of a database may be set as a Batch Mode process to limit its impact on other (non-batch) processes running on the system. Specifically, a Batch Mode process is prevented from overwhelming the database cache with the database blocks that it reads or modifies. For example, a data compaction utility might appropriately run in Batch Mode.
A Batch Mode process is not the same as a jobbed process. A jobbed process is generated using the JOB command. A jobbed process is a non-interactive process running in background.
You can use the %SYSTEM.Util.SetBatch() method to establish a process as executing in batch mode. You can specify a process by its pid, or default to the current process. SetBatch() takes a Boolean argument: 0=direct mode (the default), 1=batch mode. SetBatch() returns the prior mode setting.
Process priority determines how multiple concurrent processes compete for CPU resources. A process with a higher priority has preferential access to CPU time.
Priority is an integer value. The range of integer values is platform-dependent, as follow: Windows has a priority range of 1 to 15, with NORMAL=8. UNIX® has a priority range of -20 to 20, with NORMAL=0. Commonly, only three integer values are used: LOW, NORMAL, and HIGH. NORMAL priority is the default for user processes. NORMAL priority uses load balancing to adjust CPU usage.
Changing the priority of a process is almost never needed and can compromise system stability.
The SetPrio() Method
You can use the %SYSTEM.Util.SetPrio() method to change the priority for the current process or another process identified by pid. You specify a positive or negative integer to increment or decrement the current priority by that amount. On Windows, the minimum priority is 1; attempting to decrement a priority to less than 1 sets priority to 1. NORMAL priority is 8. The maximum priority is 15. SetPrio() returns the new priority level set. (Note that attempting to increment past 15 may reset priority to 1 or have other unpredictable results. A SetPrio() return value of >15 does not reflect the actual priority set.)
The ^%PRIO Utility
You can use the older ^%PRIO utility to determine the priority for the current process and to set the priority to a LOW, NORMAL, or HIGH value.
To determine the current priority, you can issue the following command: DO ^%PRIO. A subsequent argumentless WRITE command will return the current priority as follows: %PRIO=8.
To set the priority of the current process, issue one of the following commands: DO LOW^%PRIO, DO NORMAL^%PRIO, or DO HIGH^%PRIO (commands are case-sensitive). The set priority values returned (on Windows) are: LOW=4, NORMAL=8, HIGH=13.
SetBatch(1) does not change the current process priority. However, if a process is in Batch Mode (1), using the above commands to raise the current process priority changes the process mode from Batch Mode (1) to Direct Mode (0).
To set both the Batch Mode and the priority for the current process, specify DO SET^%PRIO(priority,mode), where priority,mode is a case-sensitive string, with priority=LOW, NORMAL, or HIGH, and mode=BATCH or NOBATCH. You can specify either one or both of the comma-separated options. For example: DO SET^%PRIO("LOW,BATCH"). This command allows you to change the process priority without affecting the mode status of a Batch Mode process.
Jobbed Process Priority
The JOB command provides an option to set the priority for a jobbed (background) process. If not specified, the child process takes the parent process base priority adjusted by a system-defined job priority modifier. For example, on Windows a parent process with NORMAL priority (priority=8) initiates a child process with a priority=7, due to the job priority modifier. A jobbed process with a priority of HIGH competes on an equal basis with interactive processes for CPU resources.