Mail Archives: djgpp/1997/01/16/06:32:44
On Thu, 16 Jan 1997, x DOT pons AT cc DOT uab DOT es wrote:
> I am writting a program that should be interrupted after 't' seconds of
> execution. During this time, the user should be able to interact with
> my program (entering keyboard data).
Define a handler for the signal SIGALRM and call library function `alarm'.
A call like "alarm (10);" will cause SIGALRM to be generated 10 seconds
from now. When that happens, your handler is called, and you may do
whatever pleases you there, including keyboard input. When your handler
returns, the program will resume at the point it was interrupted. The
library reference for `alarm' has the rest of details. If you never
before wrote a signal handler, please also read the docs of library
function `signal'.
Note that due to specifics of signal support in DJGPP, your handler is
only called when the program is in protected mode and touches some of its
data, so in reality the program might be interrupted not exactly at the
moment you want but somewhat later. The latency depends on the amount of
time your program spends doing DOS I/O or real-mode BIOS calls. The
above approach is a good technique if you don't care much about the
accuracy of the moment when the program is interrupted.
- Raw text -