12 Multiple Task Programming

HP-UX Background Processing

Besides the multi-tasking features offered inside Eloquence, you have the possiblity to use HP-UX background processes. Within the HP-UX environment there are two options. The first option is to run your Eloquence program in HP-UX background. The second option is to run your Eloquence program in HP-UX foreground and then switch it to background. Each option is described below. All commands discussed are executed from the HP-UX prompt.

Option One

Eloquence distinguishes between two major operating modes: Interactive mode and background mode. Interactive mode is assumed when stdout is connected to a tty device (e.g. your terminal). Background mode is assumed when stdout is connected to anything else but a tty device (e.g. pipe, file). In background mode, the screen buffer is not updated to your terminal. All screen output is put only in the internal screen buffer.

You may run Eloquence from the HP-UX prompt using the following syntax:

eloqcore [-b] program name [outfile] [infile] [&]

If you redirect stdout to file or pipe, Eloquence will automatically run in background mode. Specifying the


switch in the command line will put Eloquence in background mode independently of the output device.

If you execute the PRINTER IS STDOUT statement in your program, you can redirect printed output into file or pipe. The BACKGROUND function returns 1 if operating in background mode.


   FOR I=1 TO 10

   eloq SAMPLE | lp &
NOTE: If run from cron, at or batch, Eloquence will operate in background mode. If output from an Eloquence program is piped to another command (for example, "eloq TEST | lp &", terminal output is automatically suppressed. The -b is thus not necessary, but the PRINTER IS STDOUT is.

Option Two

Under this option, you start your Eloquence program from HP-UX foreground and then switch it to background.

The first step in this process is to define a suspend character. The suspend character is used to suspend the execution of a program so that it can be put into background. To define a suspend character, execute the following command sequence:

stty susp susp char

Replace susp char by pressing any key combination. For example, stty susp CTRL Z. The CTRL Z displays as ^Z.

Once a suspend character is defined, start the program in foreground by issuing the command:

eloqcore program name

Replace program name with the name of an Eloquence program. You do not have to specify the extension .PROG.

The next step is to switch the program to HP-UX background processing. To make this switch perform the following steps:

  1. Suspend the program, using the pre-defined suspend character (for example, CTRL Z). When the suspend character is pressed, the HP-UX prompt appears.

  2. Execute the command bg [%process number]. If bg is entered by itself, the program currently suspended will be put in background in the first available process. If the parameter %process number is added, the program currently suspended will be put in background in the specified process. Once the program is in background, it resumes execution. While the program is executing in background, you can do anything in foreground except logout. You can have several programs running in background.

To switch a program in background to foreground, use the following command:

fg [%process number]

The optional %process number is only needed if more than one program is running in background. The process number indicates in which background process the program is running.

Starting Eloquence from an Eloquence program.

It is also possible to start Eloquence from an Eloquence program. This Eloquence will terminate if the program is terminated.

1010 ! This program is intended to control FG,TEST in
1020 ! background.
1030 !
1040 ! Run eloqcore process, wait until finished
1050 !
1060       Info$="'PASS #1'"
1070      COMMAND "!INFO="&Info$&";export INFO;eloqcore BG,TEST 2>&-"
1080       COPY "BG,TEST"
1090 !
1100 ! Start eloqcore process, run asynchroneously
1110 !
1120       Info$="'PASS #2'"
1130       COMMAND "!INFO="&Info$&"; export INFO;eloqcore BG,TEST  </dev/null >/dev/null 2>&1 &"
1140       END

1010 ! This program is intended to run in the background
1020 ! controlled by a foreground eloquence (FG,TEST)
1030 !
1040 ! Purge file and recreate
1050       ON ERROR GOTO E
1060       PURGE "BG,TEST"
1070 E:    OFF ERROR
1080       CREATE "BG,TEST",0
1090       ASSIGN #1 TO "BG,TEST"
1100 !
1110 ! Put some data into file
1120       PRINT #1;"DATE = "&DATE$
1130       PRINT #1;"TIME = "&TIME$
1140       PRINT #1;"PID  = "&VAL$(PID)
1150       PRINT #1;"TASK = "&VAL$(TASKID)
1160       PRINT #1;"INFO = "&GETENV$("INFO")
1170 !
1180 ! Do some work
1190       Start=CLOCK
1200       FOR I=1 TO 10000
1210       NEXT I
1220       Seconds=(CLOCK-Start)/1000
1230       PRINT #1;"USED = "&VAL$(Seconds)
1240 !
1250 ! Done
1260       ASSIGN * TO #1
1270       END

Eloquence Language Manual - 19 DEC 2002