Monitoring Changes in Process Status

A process can monitor the status of its offspring by waiting on its own EXCEPTIONEVENT task attribute. This method works because, when the status of a process changes, the system automatically causes the EXCEPTIONEVENT of the parent of the process, unless the EXCEPTIONTASK of the offspring has been changed.

If you design a process to wait on its own EXCEPTIONEVENT, it can resume execution and check the status of its offspring each time the EXCEPTIONEVENT is caused. For example, to wait for a task to terminate, the parent process can execute the following ALGOL statement:

WHILE T.STATUS GTR VALUE(TERMINATED) DO
   WAITANDRESET(MYSELF.EXCEPTIONEVENT);

Note that a WAITANDRESET statement is used rather than a simple WAIT statement. If a simple WAIT statement were used, then the WHILE loop would execute an infinite number of times after the first time the EXCEPTIONEVENT was caused.

The most typical reason for using such WAIT statements is to prevent critical block exits for ALGOL or COBOL programs that initiate asynchronous tasks. Critical block exits are discussed in Understanding Interprocess Relationships.

It is not necessary to take steps to prevent critical block exits in WFL. WFL automatically waits at the end of each block if any processes initiated by statements in the block are still in use. However, there can be other reasons for a WFL job to wait on the termination of an asynchronous task. For example, suppose you have an application consisting of three programs. The first two programs create files that are used as input by the third program. The following WFL job runs the first two programs in parallel and waits for them to complete before initiating the third program:

100 ?BEGIN JOB;
110   TASK T1, T2, T3;
120   PROCESS RUN OBJECT/RUNEX [T1];
130   PROCESS RUN OBJECT/TADCOM [T2];
140   WHILE T1 ISNT COMPLETED OR T2 ISNT COMPLETED DO
150     WAIT;
160   PROCESS RUN OBJECT/DIALUP [T3];
170 ?END JOB

Note that the statement at line 150 is simply WAIT, rather than WAITANDRESET (MYSELF.EXCEPTIONEVENT) as it would be in ALGOL. This difference arises because WFL has no syntax for directly accessing the EXCEPTIONEVENT task attribute, or events in general for that matter. However, the simple WAIT in WFL has the effect of implicitly waiting on and resetting the EXCEPTIONEVENT.

WFL provides some other useful expressions for monitoring process status. You can design a WFL job to wait for a task to terminate, to wait for the task to assume a particular status, or to wait for any attribute of the task to assume a desired value. For details, refer to the discussion of the WAIT statement in the Work Flow Language (WFL) Programming Reference Manual.