Guardian Programmer's Guide

Table Of Contents
Writing a Command-Interpreter Monitor ($CMON)
Guardian Programmer’s Guide 421922-014
23 - 21
Controlling the CPU of a New Process
Controlling the CPU of a New Process
The users choice of the CPU in which to run the new process is received by the
$CMON process in the PROCESSCREATION^MSG.PROCESSOR variable. If the
user did not specify a CPU, then this value contains -1.
The $CMON process can set the CPU number in the reply to any valid process
number or -1 for the CPU in which the primary process of the TACL process is running.
The following example shows how $CMON can segregate processes into those that
require priority response and those for which response time is not critical. Priority-
response processes will run in CPUs 0, 2, and 4; other processes will run in CPUs 1, 3,
and 5.
To keep the example simple, the requested priority is used to determine the speed of
response required. A typical $CMON process might, for example, use a list of program
names that run as priority-response processes. In this example, those processes with
a requested priority greater than 150 are priority-response processes. Once the group
of CPUs is established for a given process, the specific CPU is chosen on a round-
robin basis.
CALL READUPDATEX(RECV^NUM,SBUFFER,RCOUNT,BYTES^READ);
IF BUFFER[0] = -52 THEN
BEGIN
PROCESSCREATION^MSG ':=' SBUFFER FOR
$LEN(PROCESSCREATION^MSG);
! Limit process priority to 175:
IF PROCESSCREATION^MSG.PRIORITY > 175
THEN PROCESSCREATION^ACCEPT.PRIORITY := 175
ELSE PROCESSCREATION^ACCEPT.PRIORITY := 0;
! Sort processes into priority and nonpriority response
! and allocate to priority response and nonpriority
! response processors:
IF PROCESSCREATION^MSG.PRIORITY > 150
THEN
BEGIN
PRIORITY^CPU := PRIORITY^CPU + 2;
IF PRIORITY^CPU = 6 THEN PRIORITY^CPU := 0;
PROCESSCREATION^ACCEPT.PROCESSOR := PRIORITY^CPU;
END
ELSE
BEGIN
NONPRIORITY^CPU := NONPRIORITY^CPU + 2;
IF NONPRIORITY^CPU = 7 THEN NONPRIORITY^CPU := 1;
PROCESSCREATION^ACCEPT.PROCESSOR := NONPRIORITY^CPU;
END;