From: Jason Green Newsgroups: comp.os.msdos.djgpp Subject: Re: Signal & setitimer Date: Sun, 07 May 2000 20:18:02 +0100 Organization: Customer of Planet Online Lines: 105 Message-ID: References: <200005051818 DOT OAA05711 AT indy DOT delorie DOT com> NNTP-Posting-Host: modem-56.dextroamphetam.dialup.pol.co.uk Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: newsg2.svr.pol.co.uk 957727120 3262 62.136.90.56 (7 May 2000 19:18:40 GMT) NNTP-Posting-Date: 7 May 2000 19:18:40 GMT X-Complaints-To: abuse AT theplanet DOT net X-Newsreader: Forte Agent 1.7/32.534 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Eli Zaretskii wrote: > > From: Frederic Cazenave > > I have written a small progranm to test setitmer. > > It's appear this code run correctly on a unix system but > > not under DOS. > > Under UNIX the timer is reactivate every 10 seconds, but > > under dos the timer is active the first time but after is never > > reactivate. > > I cannot reproduce this with your test program on my machine. On what > OS did you try this, and what version of DJGPP do you use? I have re-written the test program (pasted below) to prove that setitimer() is not somehow corrupting the timeout variable, and to remove any suspicion about alarm(), which is also a libc function. I'm not sure exactly what the expected behaviour of this program *should* be (can someone clarify this) but the actual behaviour is definitely not consistent. This is with DJGPP v2.03 under Windows 95, compiled with gcc 2.95.2 using the command: gcc -Wall test.c -o test In a normal DOS box the program runs (until aborted with Ctrl-C). Unless I run using redir, in which case it terminates immediately with exit code 1: D:\CODE\TEST>test setitimer0123!!!!4!!!!!!!!!!!!!!!!!!!5!!!!!!!!!!!!!!!!!!!6!!!!!!!!!!!!!!!!!!!7!! !!!!!!!!!!!!!!!!!8!!!!!!!!!!!!!!!!!!!9 setitimer0123!!!!4!!!!!!!!!!!!!!!!!!!5!!!!!!!!!!!!!!!!!!!6!!!!!!!!!!!!!!!!!!!7!! !!!!!!!!!!!!!!!!!8!!!!!!!!!!!!!!!!!!!9 setitimer0123!!!!4!!!!!!!!!!!!!!!!!!!5!!!!!!!!!!!!!!!!!!!6!!!!!!!!!!!!!!!!!!!7!! !!!!!!!!!!!!!!!!!8!!!!!!!!!!!!!!!!^C Exiting due to signal SIGINT INTR key Pressed at eip=0000897d D:\CODE\TEST>redir -x -t test Exit code: 1 Elapsed time: 0.280 seconds A couple of times when pressing the Ctrl key, Windows popped up a box saying "The program encountered a general protection exception". After this Windows becomes unstable and requires a reboot. Running the program from UltraEdit gives a different result and the timing between printing digits varies +/- a fraction of a second: setitimer0123456789 setitimer0123456789 setitimer0123456789 setitimer0123456 UltraEdit seems to use the programs c:\windows\system\conagent.exe and c:\windows\system\redir32.exe to create a shell for test.exe and capture its output. Each running of test.exe from UltraEdit leaves instances of Redir32 and Winoldap listed when I do Ctrl-Alt-Del even though the test program appears to exit gracefully. This is the test code (modified from the original post): #include #include #include #include #include void handle_sigalrm(int sig) { printf("!"); fflush(stdout); signal (SIGALRM,handle_sigalrm); } int main(void) { static struct itimerval timeout; int i; signal (SIGALRM,handle_sigalrm); while(1) { timeout.it_interval.tv_sec=0; timeout.it_interval.tv_usec = 0; timeout.it_value.tv_sec=5; timeout.it_value.tv_usec = 0; printf("\nsetitimer"); setitimer(ITIMER_REAL,&timeout,NULL); for (i=0; i<10; i++) { sleep(1); printf("%d", i); fflush(stdout); } } return(0); }