Xref: utzoo comp.lang.c:16795 comp.unix.questions:12098 comp.unix.wizards:14984 Path: utzoo!yunexus!torsqnt!dptcdc!jarvis.csri.toronto.edu!mailrus!uflorida!haven!h.cs.wvu.wvnet.edu!b.cs.wvu.wvnet.edu!dymm From: dymm@b.cs.wvu.wvnet.edu (David Dymm) Newsgroups: comp.lang.c,comp.unix.questions,comp.unix.wizards Subject: Interrupt Handler in 'C' Message-ID: <319@h.cs.wvu.wvnet.edu> Date: 8 Mar 89 17:11:18 GMT Article-I.D.: h.319 Sender: news@h.cs.wvu.wvnet.edu Lines: 69 I POSTED THIS THE OTHER DAY --- FROM THE MAIL RECEIVED (THANK YOU VERY MUCH), I REALIZE THAT I DID A POOR JOB OF EXPLAINING MYSELF. SO I WILL POST THIS AGAIN WITH A DIFFERENT EXPLANATION: I would like to write an interrupt handling mechanism in 'C' (on BSD 4.2 Unix) to work in the following way: 1) Set up the signal facility: signal (SIGALRM, alarm_handler) 2) Set the alarm: ualarm (100000, 0) <== This will send a signal after 100,0000 microseconds. 3) The interrupt handler "alarm_handler" (a separate function) is called with the signal mechanism when the alarm timer times out. Let's call "location A" the place where we were in the code when we were interrupted by the timer. When "alarm_handler" has finished its local processing, it resets the alarm. At this point, I do NOT want to return control back to where the interrupt occurred!!!! Instead, I want to "longjmp" to a separate "function B" When "function B" has completed its work, I want to return to "location A". 4) However while function "B" is doing its thing, the alarm may again signal an interrupt, causing the above actions to happen again. The longjmp mechanism prevents continually pushing the call to function "B" on the system stack. The question is: How do I return to "location A" ??? I have looked at the "sigstack" mechanism, and also at the definitions for "sigcontext" and "sigstack" in "signal.h". But I do not see how to put this all together to accomplish my task. The system saves the state of the process on the signal stack when "signal" causes control to jump to "alarm_handler". How do I get at that information, AND more importantly, how do I use that information to accomplish my task. --------------------------------------------------------------- The following questions were raised by people who sent me mail: A) Why do a longjump to function "B" --- just call the function ??? If I "call" function "B", the function call gets pushed onto the system stack. The problem is that the above actions ( alarm timeout --> "alarm_handler" --> longjmp to "B" ) can occur a number of times. If I continually call function "B", then the stack will continue to grow. However whether I call "B" or longjmp, this does not help me in returning to location "A" !!! David Dymm Software Engineer USMAIL: Bell Atlantic Knowledge Systems, 145 Fayette Street, Morgantown, WV 26505 PHONE: 304 291-9898 (8:30-4:30 EST) USENET: {allegra,bellcore, cadre,idis,psuvax1}!pitt!wvucsb!dymm INTERNET: dymm@b.cs.wvu.wvnet.edu