Re: Is it possible to timeout 4GL?
Posted in 1994
->: ->John Powell (jpowell@cv.hp.com) originally wrote: ->: -> ->: ->Hello, ->: -> We are looking for a way to timeout 4GL programs when there is no terminal ->: ->response after n minutes. The problem we are having is as follows: ... ->:Alan Popiel (alan@po.den.mmc.com) answered: ->: There is no way to do this completely within 4GL. I have done something ->: similar thru the use of C subroutines called from 4GL. ->: ->: If you want to converse off-line, I can tell you some of the things I have ->: done in a Sun-OS environment that come close to what you want. While I ->: can't say for certain, I would assume that similar capabilities are ->: available under HPUX. ->Richard Spitz (spitz@GANS2X.ana.med.uni-muenchen.de) then requested: -> ->Hi Alan, -> ->could you please converse on-line in this group? I am also very interested ->in solutions to the timeout problem. -> ->Regards, Richard At the request of my friend Richard, I will offer what I have to the group at large. I suggested going off-line because the few answers I have only partially address the problem as stated. Even so, my anwsers are somewhat long. 1. To paraphrase Jonathan Leffler's answer to a similar question: The reason you can't do this completely within 4GL is that 4GL only does one thing at a time. If your 4GL program is waiting for input, it is just WAITING; it cannot simultaneously be counting down a timer to accomplish the timeout. 2. The answer that I have in hand was developed to solve a different problem: Users would use Sun OpenWindows mouse actions to quit a window running my 4GL program, named VITAL. In this case, the program could not do some necessary clean-up before it exited. My solution was to have a colleague write a C subroutine to trap certain Unix signals. The trapper called a 4GL function that did the clean-up and exited. 2.a. The trapper subroutine in C: /* module i_quitrap.c * * i_quit_trap() Performs call to UNIX system services: * signal(SIGHUP,handler) and signal(SIGQUIT,handler); * Designed to catch when a user quits a UNIX window that is running VITAL. * * $Author: gammill $ * $Date: 90/04/26 $ * $Revision: 1.0 $ * * syntax: * CALL i_quit_trap() * * RETURNING arguments: * None. * * On the user quitting a window, shut_down() will be called. */ #include <signal.h> /* profile */ void shut_down(); void i_quit_trap() { signal(SIGHUP,shut_down); signal(SIGQUIT,shut_down); } /* end module i_quitrap.c */ 2.b. To use this trapper, the 4GL must "CALL i_quit_trap ()" during its initialization code. Function "shut_down()" is simply a 4GL function that performs the necessary database clean-up, then performs EXIT PROGRAM. Notice that as it stands, this does NOT address time-out. 3. To handle time-out, I suggess the following approach. Warning: I have NOT tried this in Unix, but it seems like it should work. (This is why I did not broadcast this originally!) However, I have done this under the Gould OS, which is similar to Unix. a. Have your 4GL program "CALL i_quit_trap ()" during initialization. b. Include 4GL function "shut_down()" to neatly shut down your program. c. Have your program periodically call C subroutine "mark_time()". The 4GL program must then call this subroutine on a regular basis, at least more frequently than the time-out interval. Depending on the complexity of the program, calls might need to be included at several places. d. Subroutine "mark_time()" is designed to do the following: (1) On the FIRST call, it spawns** a process "timer". The subroutine must remember the process-id** of the spawned process in a static variable. (2) On subsequent calls, the subroutine sends some signal to the "timer" process. e. The "timer" process is a separate program, written in C. (1) When it starts, it remembers the process-id of the process that started it. It then starts an internal count-down timer. Then it waits, preferably using the library function "sleep(seconds)". (2) Whenever the program receives the signal mentioned in d(2), it resets its internal count-down timer. (3) If the internal timer expires, then the program sends signal SIGQUIT to the process that started it, using the process-id remembered in step e(1), and then exits. 4. Note that if the user leaves the 4GL program idle, it will process until it gets to some keyboard wait and then just wait. Thus it will not call "mark_time()". So "timer" will eventually expire, send a SIGQUIT to the original program, and then exit itself. 5. The disadvantage to this approach is that it requires a separate Unix process to do the timing. It is probably possible to have a single timer process for all programs of a given type, but that gets much more complex. The programs must have a way of getting the timer process id, the timer must maintain a list of timed-process ids with their associated timer counts, etc., etc. **This is the one detail that kept me from posting to the net earlier. This was easy under Gould OS. Does anyone know how to do this under Unix? There must be a way! Regards, Alan ___________________________ ______________________| R. Alan Popiel |__________________________ \\ Internet: | Martin Marietta, SLS | / \\ alan@den.mmc.com | P.O. Box 179, M/S 3810 | Std disclaimers apply. / )Voice: | Denver, CO 80201-0179 USA | ( / 303-977-9998 |___________________________| (But you knew that!) \\ /________________________) (____________________________\\