Mail Archives: djgpp/2000/05/07/15:20:47
Eli Zaretskii <eliz AT delorie DOT com> wrote:
> > From: Frederic Cazenave <cazenave AT radar DOT mcgill DOT ca>
> > 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 <stdlib.h>
#include <stdio.h>
#include <signal.h>
#include <sys/time.h>
#include <unistd.h>
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);
}
- Raw text -