From: stockton AT bcm DOT tmc DOT edu (David Stockton) Message-Id: <199612192326.RAA15234@ginger.imgen.bcm.tmc.edu> Subject: Re: SIGINT handling & stdio To: feeley AT raptor DOT IRO DOT UMontreal DOT CA (Marc Feeley) Date: Thu, 19 Dec 1996 23:26:38 +0000 (GMT) Cc: djgpp AT delorie DOT com (DJGPP Mail List) In-Reply-To: from "Marc Feeley" at Dec 12, 96 10:06:10 am Reply-to: stockton AT bcm DOT tmc DOT edu Organization: Molecular and Human Genetics, Baylor College of Medicine Phone: (713)798-4795 x-fax-number: (713)798-5073 x-phone: (713)798-4795 MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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 > #include > > 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