From: Brian Bebeau on
On 2/7/2010 11:43 AM, K-mart Cashier wrote:
> I have a program that continuously reads in a text file. What I want
> to do is have the program exit when I press either ctrl-z or ctrl-c.
>
> How would I go about trapping ctrl-c/ctrl-z in this case?

You need to catch the SIGINT and SIGSTOP signals. Set a flag in the
signal handler that you check later to exit the loop. If you don't
already have ctrl-c and ctrl-z set to generate these signals, you'll
have to use termios to set them:

term.c_cc[VINTR] = \003;
term.c_cc[VSTOP] = \032;

--
Brian Bebeau
bbebeau (at) computer.org