Terminating a Process

You can interactively terminate a process by entering the DS (Discontinue) system command. You can design a program to terminate a process by assigning the STATUS task attribute a value of TERMINATED. The following is a WFL program that terminates a task if it becomes suspended:

100 ?BEGIN JOB ACCOUNTS/JOB;
110   JOBSUMMARY = SUPPRESSED;
120   CLASS = 2;
130 TASK T;
135 BOOLEAN DONE;
140 PROCESS RUN OBJECT/DAILY/ACCOUNTS [T];
150 WHILE NOT DONE DO
160 BEGIN
170   WAIT;
180   IF T IS STOPPED THEN
190      BEGIN
200        T(STATUS = TERMINATED);
210        MYSELF(JOBSUMMARY = UNCONDITIONAL);
220      END;
230   IF T IS COMPLETED THEN
240      DONE:= TRUE;
250 END;
260 ?END JOB

The presumption behind this WFL program is that OBJECT/DAILY/ACCOUNTS is a program that does not normally become suspended at any point in its run. If this particular program becomes suspended, it means that something has gone wrong and it is something that an operator cannot easily fix. Further, it is assumed that job queue 2, which this job is initiated from, has a mix limit of 1. Thus, if OBJECT/DAILY/ACCOUNTS becomes suspended, it is impossible for any more WFL jobs to be initiated from that job queue until an operator notices the situation and discontinues the process.

The WHILE statement at lines 150 to 250 is included to prevent this job from ever uselessly blocking up the job queue. Within the WHILE statement, the WAIT statement at line 170 causes the WFL job to wait until its own EXCEPTIONEVENT is caused. The system automatically causes the job's EXCEPTIONEVENT when the STATUS value of any of the job's offspring changes. When the status value of the offspring changes, the statement at line 180 uses the task state expression to determine if OBJECT/DAILY/ACCOUNTS is suspended; if so, then the statement at line 200 assigns a STATUS of TERMINATED to discontinue OBJECT/DAILY/ACCOUNTS. The statement at line 210 causes printing of the job summary. For information about job summaries, refer to Determining Process History.

The statement at lines 230 to 240 causes the loop to be exited when OBJECT/DAILY/ACCOUNTS terminates (whether it terminated normally or was discontinued).