Mail Archives: djgpp/1996/12/19/18:34:29
Marc,
I ran your program on djgpp version 2.0 and Windows 95 and it pretty
much worked as expected. The interupt handler was not called until a
carriage return (That is if I typed "hello^Cthere" I would get "interrupt
got 116, got 104, got 101, got 114, got 101, got 10"). If I tried putting
a printf in user_signal_handler() it somehow ended up putting the printed
characters in my input stream, which I do not understand. But as far as
the interrupt being serviced it worked almost as expected.
- David
>
> I want to port a program that uses stdio and handles ctrl-c interrupts
> with signal(SIGINT,...). The program below is a small example. It
> seems that when getchar is called, a ctrl-c will NOT call the signal
> handler; the program simply terminates. This is strange because if I
> replace getchar with getkey then the program works fine.
> Unfortunately I can't use getkey in my program because the input is
> not necessarily from the console (it might be a redirection).
>
> Any suggestions? I'm sure this problem must have come up before but
> I can't find a suitable answer in the FAQ or the DJGPP doc.
>
> Marc
>
>
> #include <stdio.h>
> #include <signal.h>
>
> int intr = 0;
>
> void user_signal_handler (void) { intr = 1; }
>
> void main (void)
> {
> int c;
> signal (SIGINT, user_signal_handler);
> while ((c=getchar()) != 'q')
> {
> if (intr) { printf ("interrupt\n"); intr = 0; }
> printf ("got %d\n", c);
> }
> }
>
>
Marc,
I ran your program on djgpp version 2.0 and Windows 95 and it pretty
much worked as expected. The interupt handler was not called until a
carriage return (That is if I typed "hello^Cthere" I would get "interrupt
got 116, got 104, got 101, got 114, got 101, got 10"). If I tried putting
a printf in user_signal_handler() it somehow ended up putting the printed
characters in my input stream, which I do not understand. But as far as
the interrupt being serviced it worked almost as expected.
- David
- Raw text -