Interprocess Communication:Programmer's Guide 900 Series HP 3000 Computers ABCDE HP Part No. 32650-90019 Printed in U.S.A.
The information contained in this document is subject to change without notice. Hewlett-Packard makes no warranty of any kind with regard to this material, including, but not limited to, the implied warranties of merchantability or tness for a particular purpose. Hewlett-Packard shall not be liable for errors contained herein or for direct, indirect, special, incidental or consequential damages in connection with the furnishing or use of this material.
Printing History The following table lists the printings of this document, together with the respective release dates for each edition. The software version indicates the version of the software product at the time this document was issued. Many product releases do not require changes to the document. Therefore, do not expect a one-to-one correspondence between product releases and document editions. Edition Date Software Version First Edition November 1987 A.01.
List of E ective Pages The List of E ective Pages gives the date of the current edition, and lists the dates of all changed pages. Unchanged pages are listed as \ORIGINAL". Within the manual, any page changed since the last edition is indicated by printing the date the changes were made on the bottom of the page. Changes are marked with a vertical bar in the margin. If an update is incorporated when an edition is reprinted, these bars and dates remain.
Chapter 1 Chapter 2 Chapter 3 Chapter 4 Chapter 5 Chapter 6 Chapter 7 Appendix A Appendix B Appendix C Appendix D What Is Interprocess Communication? de nes Interprocess Communication (IPC) and describes the advantages of using it. IPC Using Job Control Words and Other Variables discusses the use of prede ned and user-de ned variables (including Job Control Words) in performing IPC. IPC Using File System Intrinsics discusses how to perform IPC using features of the MPE/iX le system, especially intrinsics.
Contents 1. What is Interprocess Communication? Purposes of IPC . . . . . . . . . . . . . . . . . . . . . . . . . . . Ways to Perform IPC . . . . . . . . . . . . . . . . . . . . . . . . . 1-1 1-2 2. IPC Using Job Control Words and Other Variables Types of Variables . . . . . . . . . . . . . . . . . . . Relationship of JCWs and Variables . . . . . . . . . . . . Variable Intrinsics . . . . . . . . . . . . . . . . . . . . HPCIPUTVAR . . . . . . . . . . . . . . . . . . . . HPCIGETVAR . . . . . . . . . . . .
4. Special Cases of IPC Multiple Concurrent Readers or Writers Preventing Deadlocks . . . . . . . . Writer Identi cation . . . . . . . . . Extended Wait . . . . . . . . . . . Timeouts . . . . . . . . . . . . . Nondestructive Reads . . . . . . . . Forcing Records To Disc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
B. Sample Programs: WAIT I/O C. Sample Programs: NOWAIT I/O D. Sample Programs: Software Interrupts SPL Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . Pascal Examples . . . . . . . . . . . . . . . . . . . . . . . . . . .
Figures 3-1. IPC Processing . . . . . . . . . . . . . . . . . . . . . . . . . . .
1 What is Interprocess Communication? Interprocess Communication (IPC) is a facility of the MPE/iX operating system that permits multiple processes to pass information among themselves. Large tasks that have been broken into independent processes can use IPC to synchronize their actions and exchange data. There are several ways you can implement IPC on MPE/iX. Purposes of IPC IPC is a useful tool for improving the performance of your system in a variety of complex processing situations.
Ways to Perform IPC A simple method of performing IPC within a single job or session is the use of variables and Job Control Words (JCWs). This feature is described in Chapter 2. The le system intrinsics provide the most powerful method of performing IPC. These intrinsics can be used to communicate between a process and any other process; the processes need not be part of the same process tree or running in the same job or session. Communication takes place through the use of message les.
2 IPC Using Job Control Words and Other Variables Processes belonging to the same job or session can communicate with each other through session-level variables. Job Control Words (JCWs) are a subset of session variables. All session variables, including JCWs, reside in the session variable table. Note Variables are used in the same way in both jobs and sessions. In this chapter, the term \session variable" is used to refer to both job-level and session-level variables.
context of their use in interprocess communication. For a complete discussion of how to set up, use, change, and delete variables and JCWs, refer to Command Interpreter Access & Variables Programmer's Guide (32650-90011). :SETVAR Adds or alters a variable in the variable table. The value can be Boolean, string, or 32-bit integer. :SETJCW Adds or alters a JCW in the variable table. The value must be an integer in the range 0 through 65535.
3 Boolean variable HPCIGETVAR The HPCIGETVAR intrinsic scans the variable table for a given variable and returns its value. The intrinsic call could be: HPCIGETVAR(VARNAME,STATUS,KEYWORD,KEYVALUE); where VARNAME is a valid MPE/iX variable name. The status of the procedure is returned in STATUS. The KEYWORD parameter has the same meaning as in HPCIPUTVAR; refer to the description above. HPCIDELETEVAR You use HPCIDELETEVAR to remove a variable from the variable table.
:SHOWVAR Use this command to display a selected variable or variables from the variable table. This command displays JCWs as well as standard variables. Entering :SHOWVAR without parameters shows you a list of all variables and values that you have set. You can enter a variable name (or more than one, separated by commas) to see the variable's value. You can also use \wild card" characters such as ?, #, [m-n], and @.
Using User-Defined JCWs for Interprocess Communication MPE/iX allows you to establish and manipulate user-de ned Job Control Words. This capability overcomes one of the disadvantages of using the system-de ned Job Control Word: MPE/iX uses JCW for status information, and you cannot be sure that MPE/iX will not modify it, thus possibly changing the information you want to pass in JCW. (MPE/iX clears bits (0:2) of JCW, but the remaining bits are user-de nable.
STORELNK:=GETJCW; PUTJCW The PUTJCW intrinsic is used to establish a user-de ned JCW, or to change the value of an existing JCW. This intrinsic scans the variable table for the JCW name. The name of a user-de ned JCW must be alphanumeric, must start with a letter, and must be between 1 and 255 characters long. If the JCW name is found, the value of JCW is updated to the value passed by PUTJCW. If not found, the JCW name is added to the table and assigned the value passed with the name.
3 Error. The JCW named in JCWNAME does not exist. For more information and full syntax descriptions for the above intrinsics, refer to the MPE/iX Intrinsics Reference Manual (32650-90028). Job Control Word Commands Several MPE/iX commands are available that allow you to set, alter, or display JCWs. These are: :SETJCW This command adds a JCW to the variable table, or alters the value of an existing variable. The value must fall within the valid range for a JCW, that is, in the range 0 through 65535.
Special Considerations When your program uses both JCW and variable commands and intrinsics, there are some considerations you should keep in mind. Remember that a Job Control Word is a type of variable, but not all variables are JCWs. The variable commands and intrinsics operate on all entries in the variable table; they do not distinguish between JCWs and standard variables. On the other hand, JCW commands and intrinsics deal only with variable table entries that are agged as JCWs.
3 IPC Using File System Intrinsics There are several ways processes can communicate under MPE/iX. The most powerful is the IPC facility provided by the le system. Characteristics This type of IPC has several advantages because it is part of the le system. Most functions are performed with standard le system intrinsics that you are already familiar with. The cooperating processes nd each other through an agreed-upon le name. Thus they don't have to determine each other's process ID.
Creating a Message File Message les can be created in several ways. To create a message le with the :BUILD command, use the MSG keyword. For example, to build a message le named PAULA, enter: :BUILD PAULA; MSG When a user process opens a new le programmatically and indicates that it will be a message le, the HPFOPEN intrinsic creates the new message le. Or HPFOPEN can explicitly reference a :FILE command.
Message File Names To use IPC, processes must reference each other through a known le name. This means that the le must be in a directory that is available to all accessors. In the example in Figure 3-1, either a :BUILD must be done previously, or one process must rst HPFOPEN the le as new and FCLOSE it as permanent, to put the le in the permanent le directory. The le can be created as temporary if all accessors are running under the same job or session.
SUPERVISOR . . . . . . . . . v T I M E SERVER v v HPFOPEN "command" file HPFOPEN "command" file HPFOPEN "response" file HPFOPEN "response" file . v . FREAD "command" file . (processing) | . | (blocked) . | v IPC | (fread FWRITE "command" file --------> _ completes) v . FREAD "response" file . | . (processing) | (blocked) . | . | (fread IPC v _ completes) <--------- FWRITE "response" file v v FCLOSE "command" file FCLOSE "command" file FCLOSE "response" file FCLOSE "response" file v v Figure 3-1.
In Figure 3-1, the server can open the Command File and issue the FREAD before the supervisor opens the Command File. The server's FREAD on the Command File waits because it is the rst I/O after the open. But suppose that, after the rst command is processed, the server issues another FREAD on the Command File, and the supervisor has terminated unexpectedly. The second FREAD will receive an EOF, signaling that something is wrong.
4 Special Cases of IPC File system IPC provides several optional sophisticated features that you may nd useful. These are described below. Multiple Concurrent Readers or Writers An application may need to use multiple concurrent readers or writers. For example, multiple supervisors may need the services of the same server. The server may not be able to keep up with the requests, and so multiple copies of it may be needed to handle the incoming requests.
because the le \looks" full (no available space). Readers are not able to read, because the le \looks" empty (no real records to be read). A deadlock has occurred. To prevent such a deadlock, make the le limit larger than the number of writers; there should be room for more records than there will be writers. (You can set the limit when the le is created with the :BUILD command or the HPFOPEN intrinsic.
Another feature of extended wait also concerns opposite accessors. If a process is waiting for action by an opposite accessor, and the last opposite accessor closes the le, this will cause an EOF and \wake up" the waiting process. Refer to the discussion of \EOF Conditions" in Chapter 3 for more information about this feature. Also, see Example B-2 in Appendix B.
You can copy the message le to another le, if, for example, you want to save it after it has been read. You can do this by accessing it with the Copy Mode option (HPFOPEN Item #17, or FOPEN aoption (3:1)). You should note, however, that accessing a le in Copy Mode means that it does not have any of the special features of message les. For a description of the Copy Mode option, refer to Appendix A of this manual, or the MPE/iX Intrinsics Reference Manual (32650-90028).
5 NOWAIT I/O Sometimes a programmer wants an application to read or write a record, but does not want it to wait for I/O to complete. For such an application, waiting is wasting time when it could be doing other processing. Timeouts do not adequately address this problem. The programmer wants this application to start an I/O, continue processing immediately, and check periodically to see if the I/O has nished. MPE/iX provides a way to solve this problem with NOWAIT I/O.
Aborting NOWAIT I/O Occasionally, after a process has started a NOWAIT I/O with FREAD or FWRITE, something occurs that causes completion of that I/O to be no longer needed. Perhaps the process is \shutting down" and does not want to wait for the I/O (that is, to issue IOWAIT or IODONTWAIT). MPE/iX lets the process abort NOWAIT I/Os that have not yet completed by using FCONTROL with a controlcode of 43. A condition code of CCE is returned if the I/O was aborted; in this case, nothing more needs to be done.
6 Software Interrupts NOWAIT I/O requires an application to \poll" to see if the requested I/O has completed. Each time the check is made, there is some overhead, whether the I/O has completed or not. The application is faced with a di cult trade-o . The more often the application polls, the greater the overhead, and the poorer its overall performance becomes.
the command. When the interrupt handling procedure completes, the part of the application performing the copy resumes automatically at the statement where it left o . Software Interrupt Intrinsics Three intrinsics are speci c to software interrupts: FCONTROL with a controlcode of 48, FINTSTATE, and FINTEXIT. FCONTROL with a controlcode of 48 arms software interrupts for a particular le. It is also used by the application to tell MPE/iX the address of the application's interrupt handler.
the interrupt occurs does not complete the I/O. A CCL is returned, and FCHECK returns the message, FSERR 79--NO NOWAIT I/O PENDING FOR SPECIFIED FILE. Note If the FREAD intrinsic was called before FCONTROL with a controlcode of 48 was invoked, it would have been handled as a normal, non-software interrupt FREAD. MPE/iX starts out with software interrupts disabled. If the FREAD is satis ed, the software interrupt is postponed until interrupts are explicitly enabled.
Main Line Code For the most part, the \main line" code of a process does not need to be concerned with the I/O to message les using software interrupts. As long as interrupts are enabled, they can occur anywhere in user code. If one occurs during an MPE/iX intrinsic, the interrupt is postponed until you exit the intrinsic and re-enter the process' code. There are some exceptions.
Restrictions There are some additional limitations. Currently, software interrupts are not available directly from COBOL or on remote les. If the process contains privileged code, the interrupt handler must be privileged to handle interrupts from it, or else an ABORT 22, Invalid stack marker, will occur. If the code you want to interrupt is privileged, then your interrupt handling procedure must also be executing in Privileged Mode.
program intfrag1(input,output); type int = -32768..32767; rec = packed array [1..80] of char; var error,msg_file_num,plabel,dummy : int; msg_file_name : packed array [1..
need_another_read := true; { INTERRUPT INITIALIZATION } { { Open the file with FOPTION = old, ascii, } and AOPTION = read only } msg_file_name := 'MSGFILE1'; msg_file_num := fopen(msg_file_name,5,0); if ccode <> 2 then begin fcheck(msg_file_num,error); quit(error); end; { Arm software interrupts and pass interrupt handler} { procedure address for THIS file.
until (done); { DISARMING SOFTWARE INTERRUPTS } done := false; repeat begin { Request MPE to disarm software interrupts. } plabel := 0; fcontrol(msg_file_num,48,plabel); if ccode = 1 then { CCL } begin { { MPE could not disarm software interrupts because an } I/O was started and never completed. Abort the I/O. } fcontrol(msg_file_num,43,dummy); if ccode = 0 then { CCG } { { { { { { The I/O has progressed too far to abort.
7 Interprocess Communication Via the MAIL Facility A number of MPE V/E-based systems use the MAIL facility to direct the communication of information between processes. This information transfer, however, is restricted to upward or downward paths through the process tree structure, so that any process can communicate only with its parent or children. Between any parent/child pair, only one such transfer is allowed at any particular time.
Mail Transfer Process The transfer of mail is based upon a transaction between the sending and receiving processes that involves the following steps: 1. The sending process tests the mailbox to determine its status, that is, whether it is empty, contains a message, or is being used by the receiving process (optional). 2. The sending process transmits the mail to the mailbox. The message transferred is an array of halfwords in the sending process stack, de ned by starting location and word count.
Sending Mail A process sends mail to its parent or child with the SENDMAIL intrinsic. If the mailbox for the receiving process contains a message sent previously by the calling process but not collected by the receiving process, the action taken depends on the wait ag parameter speci ed in SENDMAIL.
Receiving (Collecting) Mail A process collects mail transmitted from its parent or a child with the RECEIVEMAIL intrinsic. If the mailbox for the receiving process is empty, the action taken depends on the wait ag parameter speci ed in RECEIVEMAIL.
The calling process currently has no other global RIN locked for itself. This could otherwise result in deadlock between two jobs/sessions.
A Features of Intrinsics for Message Files Several intrinsics have features that apply speci cally to message les. Most of these features are found in HPFOPEN and FCONTROL, but other intrinsics are used slightly di erently for message les. Intrinsics Not Allowed for Message Files Certain intrinsics are not allowed for message les. These are: FPOINT FREADDIR FREADSEEK FSPACE FUPDATE FWRITEDIR FDELETE The FSETMODE intrinsic is permitted, but ignored.
A Note On Syntax In some of the following intrinsics, a parameter contains more than one piece of information within a word. When this is the case, data elds are described in the format (n:m ), where n is the rst bit of the eld and m is the number of consecutive bits in the eld. For example, the FOPTION eld for File Type occupies bits (2:3), or bits 2, 3 and 4. Parameters not discussed in the following descriptions retain their normal value range and defaults.
User EXCLUSIVE SEMI SHARE Default Value 1 2 3 0 Meaning One reader, one writer One reader, multiple writers Multiple readers and writers Same as 1 In copy mode, the value is always 1. This feature permits processes located in di erent jobs or sessions to open the same le. Item #14, multiaccess mode; 0 - No multiaccess. The le system changes this value to 2 to allow global AOPTION (5:2) multiaccess.
Item #44, numbu ers option; NUMBUFFERS eld The number of bu ers you wish to allocate to the le. Value must be between 2 and 31; default is 2. IPC needs at least two bu ers; if fewer than two are speci ed, the eld is changed to two. Also, IPC never uses more bu ers than there are blocks in the le. If more are speci ed, the lower number is used (except in copy mode). For message les, the le system sets this value to 0. Item #46, inhibit Readers may open a message le with NOBUF if they are in copy mode.
Code Param 4 Integer 2 6 43 45 1 or 0 46 1 or 0 Description Complete all I/O; ignored in the case of message les. Set timeout interval. Indicates that a timeout interval is to be applied to a le. In the case of message les, param speci es the length of time (in seconds) that a process waits when reading from an empty le or writing to a full one. The timeout remains enabled until it is explicitly cancelled. (Refer to Chapter 4.) Write End-Of-File.
Code 47 48 Param 1 or 0 plabel Description Nondestructive read. If the param value is 1, the next FREAD by this reader will not delete the record. Subsequent FREAD calls are una ected. If the param value is 0, the next FREAD by this reader deletes the record. (Refer to Chapter 4.) Arm/disarm software interrupts. The param parameter must pass the external label (plabel ) of your interrupt procedure. If the value of param is 0, the interrupt mechanism is disabled for this le.
FFILEINFO Three values for itemvalue are speci cally for use with IPC: Item # 34 35 49 Type I16 I16 I16 Description The current number of writers. The current number of readers. Software interrupt plabel . A value of zero implies that software interrupts are not being used.
B Sample Programs: WAIT I/O This appendix contains a group of sample programs illustrating the use of File System features to perform Interprocess Communication. Included are two simple COBOL programs (Examples B-1 and B-2) that show the use of WAIT I/O for interprocess communications. For sample programs showing more complex forms of IPC, refer to Appendixes C and D. Example B-1. 001000* 001100* MSGWRTR 001200* 001300* Compiled with COBOLII.
004600 DISPLAY MSG-STAT. 004700 MOVE "F" TO DONE. 004800 PERFORM 200-GET-LINE UNTIL FINISHED. 004900 CLOSE WRITE-FILE. 005000 DISPLAY MSG-STAT. 005100 STOP RUN. 005200* 005300 200-GET-LINE. 005400 MOVE SPACES TO TERM-REC. 005500 ACCEPT TERM-REC. 005600 IF END-REC = "//" THEN 005700 MOVE "T" TO DONE 005800 ELSE 005900 WRITE OUT-REC FROM TERM-REC 006000 DISPLAY MSG-STAT 006100 IF MSG-STAT NOT = "00" THEN 006200* Error during write or file is full, stop writing. 006300 MOVE "T" TO DONE. Example B-2.
004000 88 NOTFINISHED VALUE IS "F". 004100 01 MSG-STAT PIC X(2). 004200 01 PARM PIC S9(4) COMP. 004300* 004400 PROCEDURE DIVISION. 004500* 004600 100-START-OF-PROGRAM. 004700 OPEN INPUT READ-FILE. 004800 DISPLAY MSG-STAT. 004900* 005000* Set up extended waits on read-file. 005100* 005200* The read will wait for a record to be written instead of 005300* returning an End-Of-File condition. 005400* 005500* 005600 MOVE 1 TO PARM. 005700 CALL INTRINSIC "FCONTROL" USING READ-FILE 45 PARM.
009100* 009200* 009300* 009400 B-4 Process (in this case display) the record received from the message file. DISPLAY TERM-REC.
C Sample Programs: NOWAIT I/O This appendix contains two programs (Example C-1 in COBOL, and Example C-2 in FORTRAN) which illustrate the use of NOWAIT I/O in Interprocess Communication. Software interrupts are not used in these examples; see Appendix D for sample programs illustrating their use. Example C-1.
004500 WORKING-STORAGE SECTION. 004600 01 IN-REC PIC X(80). 004700 01 TERM-REC PIC X(80). 004800 01 BACK-GROUND-MSG PIC X(17) VALUE "BACKGROUND WORK ". 004900 01 ERROR-MSG PIC X(17) VALUE "UNEXPECTED ERROR ". 005000 01 IN-FILE-NAME PIC X(9) VALUE "MSGFILE1 ". 005100 01 DONE PIC X. 005200 88 FINISHED VALUE IS "T". 005300 88 NOTFINISHED VALUE IS "F". 005400 01 PARM PIC S9(4) COMP. 005500 01 LNGTH PIC S9(4) COMP. 005600 01 IN-FILE PIC S9(4) COMP. 005700 01 LOOP-COUNTER PIC S9(4) COMP.
009600* 009700 200-PROCESSING-LOOP. 009800* 009900* Each pass through this loop we do one iteration of the "background 010000* task" and then we test to see if a message has come in. 010100* 010200 PERFORM 300-BACKGROUND-TASK. 010300 PERFORM 400-CHECK-FOR-MSG. 010400* 010500 300-BACKGROUND-TASK. 010600* 010700* This could be any background processing, but in our case it is 010800* just a display. 010900* 011000 PERFORM 700-CPU-WASTER 10000 TIMES. 011100 ADD 1 TO LOOP-COUNTER.
014600* 014700 MOVE -80 TO LNGTH. 014800 CALL INTRINSIC "FREAD" USING IN-FILE IN-REC LNGTH. 014900 IF CC NOT = 0 THEN 015000 PERFORM 900-ERROR-CONDITION. 015100* 015200 700-CPU-WASTER. 015300* 015400* This is here just to burn up time. Real work should be done here. 015500* DO NOT put a "CPU waster" like this in a real program. 015600* 015700 MOVE SPACES TO TERM-REC. 015800* 015900 900-ERROR-CONDITION. 016000 DISPLAY ERROR-MSG. 016100 CALL INTRINSIC "PRINTFILEINFO" USING IN-FILE. 016200 STOP RUN.
C C C C C C C C C C C C C C C C C C C C C CALL GETUSERMODE Open the input message file. foption = ascii, old. aoption = no wait I/O, read access. fnuminfile = FOPEN( "MSGFILE1", 5B, 4000B) IF (CCODE() .NE. 0) THEN CALL PRINTFILEINFO( fnuminfile ) STOP ' Error occured during input message file FOPEN ' END IF Open the output message file. foption = ascii, old. aoption = write access. fnumoutfile = FOPEN( "MSGFILE2", 5B, 1B) IF (CCODE() .NE.
C C C C C C C C C C C C C C C C C C C-6 STOP ' Error occured during IOWAIT ' END IF IF (condcode .EQ. 1) THEN ! EOF eof = .TRUE. END IF IF (condcode .EQ. 0) THEN Process the message that came in; in this case write it to "message file 2". FREAD and FWRITE want byte lengths to be negative. IOWAIT returns a positive byte length. We have to change the sign. tcount = - tcount CALL FWRITE( fnumoutfile, buf, tcount, 0) IF (CCODE() .NE.
C C CALL PRINTFILEINFO( fnuminfile ) STOP ' Error occured during message file FCONTROL/IOWAIT ' END IF END IF CALL FCLOSE( fnumterm, 0, 0) CALL FCLOSE( fnuminfile, 0, 0) CALL FCLOSE( fnumoutfile, 0, 0) STOP 'Successful' END Sample Programs: NOWAIT I/O C-7
D Sample Programs: Software Interrupts This appendix contains a group of sample programs illustrating a fairly complex, but very typical, use of message les and soft interrupts. There are two groups of programs, one in SPL and another in Pascal. SPL Examples Examples D-1 through D-3 are a group of SPL programs showing the use of software interrupts and message les in Interprocess Communication. A group of sample Pascal programs follows. Example D-1.
end. begin sequence:=i; timer:=clock; dateline(outdata); outdata(14):=sequence; outdata(15):=timer1(0); outdata(16):=timer1(1); fwrite(file'num,outdata,-34,0); if <> then begin fcheck(file'num,error); quit(error); end; pause(pause'val); end; Example D-2. $control uslinit << LOG SPL program to demonstrate soft interrupts in a process handling environment. >> This program opens $STDIN nowait. It opens a message file (MONTOLOG) and enables soft interrupts.
begin integer lth; lth:=ascii(temp,10,num); if lth=1 then begin num(1):=num(0); num(0):="0"; end; end; <> << >> << >> INTERRUPT HANDLER ROUTINE When an interrupt occurs on the message file (filenum), we get the time of the interrupt using the CLOCK intrinsic. The time the record was written into the message file is written as part of the record in the message file. We extract that time as well and write both times into our log file.
>> << >> << >> << >> << >> << >> << >> << >> << >> << >> D-4 In this section, we convert the proper clock bits to times which can be printed as part of the above messages. Long and involved, but that's a problem with SPL. First we must extract the timestamp from the message file record. Extract hour. temp:=outdata(15).(0:8); getasc(num,temp); move msg1(19):=num,(2); Extract minute. temp:=outdata(15).(8:8); getasc(num,temp); move msg1(22):=num,(2); Extract second. temp:=outdata(16).
<< >> << >> << >> << >> << >> << >> << >> << >> getasc(num,temp); move msg2(22):=num,(2); Extract second. temp:=time1(1).(0:8); getasc(num,temp); move msg2(25):=num,(2); Extract tenth-of-second. temp:=time1(1).(8:8); getasc(num,temp); move msg2(28):=num,(2); END of processing for TIME OF INTERRUPT message. fwrite(log'file'num,msg2,-30,0); Re-post the message file read. fread(filenum,buff,-34); Re-enable interrupts when the handler routine exits. Same effect as FINTEXIT(TRUE).
if<> then begin fcheck(file'num,error); quit(error); end else print(stat2,-18,0); << OPEN LOGFILE as an OLD ASCII file. LOGFILE is VERY IMPORTANT. If the messages in the interrupt routine are posted to the terminal (via PRINT), then we will have to wait for the FREAD on the terminal to complete before the write will complete.
>> iowait(0,,lth); print(buff1,-80,0); end; fclose(log'file'num,1,0); end. Example D-3. $control uslinit << PARENT This program is the parent process for MON and LOG.
Pascal Examples The following group of programs (Examples D-4 through D-6) show the use of message les and soft interrupts for Interprocess Communication. For a simpler example, see the sample Pascal program in Chapter 6. Example D-4. $uslinit$ program mon(input,output); { MON This program opens message file MONTOLOG and writes a data record every 2 seconds. The data record is the dateline plus the 2-word return from the CLOCK intrinsic. } type int = -32768..32767; timer = packed record hour : 0..
file_num := fopen(file_name,5,193); if ccode <> 2 then begin fcheck(file_num,error); quit(error); end else writeln('Opened OK'); pause_val := 2.0; for i:=1 to 100 do begin outdata.sequence := i; dateline(outdata.dataline); outdata.time:=clock; fwrite(file_num,outdata,-34,0); if ccode<>2 then begin fcheck(file_num,error); quit(error); end; pause(pause_val); end; end. Example D-5. $uslinit$ $standard_level 'HP3000'$ { LOG Pascal program to demonstrate soft interrupts in a process handling environment.
end; { DATA_REC is a record type which corresponds to the record written by the MON program. } data_rec = record dataline : packed array [1..28] of char; sequence : int; time : timer; end; var fle : text; i,lth,addr,parm : int; file_num_0,file_num,file_num_1 : int; logfile,file_name,file_name_1 : packed array [1..10] of char; buff,buff1 : packed array [1..
} { } { } { } timestamp:=clock; Complete I/O from message file. iodontwait(filenum,buffer); writeln(fle,buffer.dataline,' ',buffer.sequence); writeln(fle,'Time file written= ',buffer.time.hour,':', buffer.time.min,':',buffer.time.sec,':', buffer.time.tenth); writeln(fle,'Time interrupted= ',timestamp.hour,':', timestamp.min,':',timestamp.sec,':', timestamp.tenth); Restart the message file read. fread(filenum,buff,-34); Re-enable interrupts when the handler routine exits. Same as FINTEXIT(1).
} { } { } { } { } { } { fintstate(1); Open the terminal for nowait I/O. file_name_1 := 'TERM '; getprivmode; file_num_1 := fopen(file_name_1,36,2048); if ccode <> 2 then begin getusermode; fcheck(file_num_1,error); quit(error); end else writeln('Opened terminal OK'); getusermode; Open the message file. file_name:='montolog '; file_num := fopen(file_name,5,192); if ccode <> 2 then begin fcheck(file_num,error); quit(error); end else writeln('Opened MSGFILE OK'); Set up soft interrupts.
} which file had a read posted against it. file_num_0:=0; iowait(file_num_0,buff1,lth); end; close(fle,'SAVE'); end. Example D-6. $uslinit$ { PARENT This program is the parent process for MON and LOG. } program daddy(input,output); type int = -32768..32767; var prog_1,prog_2 : packed array[1..10] of char; pin,pin1,error,error1 : int; nums,items : array[1..
Index A Abnormal termination recovery from , 3-5 Aborting NOWAIT I/O , 5-2 Adding a JCW to the variable table , 2-7 Altering a JCW's value , 2-7 Altering a session variable or JCW , 2-3 Armed interrupts , 6-2 Avoiding deadlocks MAIL Facility , 7-4 B Broadcast facility , 4-1 BUILD command for recovery , 3-5 BUILD command , 3-2 C Changing the value of a user-de ned JCW , 2-6 CIERROR JCW , 2-4 Circular les , 4-4 COBOL sample programs , B-1, C-1 Collecting mail , 7-4 Command le , 3-2 Command queue , 4-1 Cont
options for , A-2 Forcing records to disc , 4-4 FORTRAN sample programs , C-1 FPOINT intrinsic , A-1 FREADDIR intrinsic , A-1 FREAD intrinsic software interrupt , 6-1 to perform IPC , 3-3 FREADSEEK intrinsic , A-1 FSETMODE intrinsic , 4-4 FSPACE intrinsic , A-1 FUPDATE intrinsic , A-1 FWRITEDIR intrinsic , A-1 FWRITE intrinsic to perform IPC , 3-3 G GETJCW intrinsic de ned , 2-5 GETJCW intrinsic , 2-2 Global RIN , 7-4 Group segment libraries , 6-5 GSL , 6-5 H HPCIDELETEVAR intrinsic , 2-2, 2-3 HPCIGETVAR
testing mailbox status , 7-2 MAIL intrinsic , 7-2 Mail transfer process , 7-2 Main line code and Message les , 6-4 Message les and program structure , 3-2 command le , 3-2 crash-proo ng , 4-4 creating , 3-2 deadlock prevention , 4-2 de ned , 3-1 le limit , 4-2 forcing records to disc , 4-4 intrinsics, special features , A-1 intrinsics which are not allowed , A-1 listing , 3-2 multiple readers or writers , 4-1 names , 3-3 non-destructive reads , 4-3 NOWAIT I/O , 5-1 recovering data , 3-5 response le , 3-2 ti
Session variables commands for , 2-3 command to display selected , 2-4 command to set or alter , 2-3 deleting , 2-4 intrinsics for , 2-2 intrinsic to remove , 2-3 intrinsic to return value , 2-3 setting , 2-2 special considerations , 2-8 Session variable table , 2-1 SETJCW command de ned , 2-7 SETJCW command , 2-2 SETJCW intrinsic de ned , 2-5 SETJCW intrinsic , 2-2 Setting a session variable , 2-2 Setting a session variable or JCW , 2-3 Setting bits in JCW with SETJCW , 2-5 Setting timeouts , 4-3 SETVAR co