Re: 4gl timer
Posted in 1997
You said: >From: rfredet@medicode.com (Rod Fredette) >Date: Fri, 07 Feb 1997 17:37:36 GMT >X-Informix-List-Id: <news.33642> > >I need the capability in a number of 4gl applications to have a timer feature >built in, so that if the program senses no activity for a given length of time >it will automatically refresh the screen with current data from the database. > This might be within a "menu", "prompt" or >"display array " statement for example. > >I have one working method in a menu statement. It calls a C function to spawn >a child process. The child then sleeps for the given length of time and sends >a SIGQUIT back to the parent, which can be easily trapped in 4gl interactive >statements. This works fine, but is not desirable as it continually spawns >numerous short lived child processes. If anyone is aware of a cleaner way or >maybe an undocumented feature in 4gl to do this I'd appreciate it. > >Interestingly, I tried having a C function simply call alarm(), but I was not >able to write a signal handler for the SIGALRM signal that worked. 4gl seems >to block any attempts to rewrite the handler for this signal. > >Any ideas would be greatly appreciated ... Marco said: >Date: Sat, 8 Feb 97 17:39:16 MET >From: Marco Greco <marcog@linux.ctonline.it> >X-Informix-List-Id: <list.13076> > >Have a look at the IIUG software archive at http://www.iiug.org/. I'm sure >there's something on using alarms with 4gl. Marco's probably right. However... I4GL uses SIGALRM internally while dealing with input -- you can't pre-empt this use in your code, I'm afraid. Using SIGQUIT is interesting -- not usual, but it will work very nicely. Good thinking! What I'd do is have the I4GL code kick off a child (using C code, not the RUN statement) and record the process ID of its child. The I4GL code calls a function which sends a signal to the child indicating 'Hi, start me a timeout' (not SIGALRM, not SIGTERM or SIGHUP; maybe SIGINT), so the child can then sleep for so many seconds, and if it wakes up because of a timeout, the child would send a signal back to the I4GL code (probably still SIGQUIT) to tell it that the timeout has occurred. Note that the child can use SIGALRM because it is not I4GL code and is not affected by I4GL's use of SIGALRM. You'd want the I4GL program to be able to send a cancel notification to the child (another signal, not SIGALRM), and to be able tell it that the I4GL code is exiting (SIGTERM or SIGHUP is appropriate). The child would need to routinely check whether its parent is still around -- ie, even when it isn't handling a pending timeout, it would wait on an alarm call, and if woken up by its own SIGALRM, it would test with signal(ppid, 0) whether its parent process is still alive. All this can be done with the signal() system call, or the POSIX-compliant alternatives, plus things like fork(), exec(), getppid(), alarm(), pause(). Yours, Jonathan Leffler (johnl@informix.com) #include <disclaimer.h>