Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Getting main loop to recognize escap key?
I have a main.cpp running in a continuous loop. I have two files open and I'
ve been stopping the program with control-c. Is this the correct way to stop
 a unix program? I'd
like to get the loop to see the escape key (without polling for it). Or, how
 can I respond to control-c in the program so that I can close files etc.?

thanks,
Jim



Report this thread to moderator Post Follow-up to this message
Old Post
James Johnson
12-15-04 02:00 AM


Re: Getting main loop to recognize escap key?
James Johnson <jjjhnson2-1779231@yahoo.com> writes:

> I have a main.cpp running in a continuous loop. I have two files open
> and I've been stopping the program with control-c. Is this the correct
> way to stop a unix program? I'd like to get the loop to see the escape
> key (without polling for it). Or, how can I respond to control-c in
> the program so that I can close files etc.?

man sigaction

Ctrl-C generates a SIGINT.

--
Måns Rullgård
mru@inprovide.com

Report this thread to moderator Post Follow-up to this message
Old Post
Måns Rullgård
12-15-04 02:01 AM


Re: Getting main loop to recognize escap key?
In article <yw1x4qiofvs2.fsf@ford.inprovide.com>,
Måns Rullgård <mru@inprovide.com> wrote:

> James Johnson <jjjhnson2-1779231@yahoo.com> writes:
> 
>
> man sigaction
>
> Ctrl-C generates a SIGINT.

Not necessarily.  That seems to be the default on Linux and Mac OS X, but
many of the Unix systems I've worked on use DEL as the default intr key.
To change it to control-C, add "stty intr '^C'" to your login script.

Report this thread to moderator Post Follow-up to this message
Old Post
Wayne C. Morris
12-15-04 02:01 AM


Re: Getting main loop to recognize escap key?
"Wayne C. Morris" <wayne.morris@this.is.invalid> writes:

> In article <yw1x4qiofvs2.fsf@ford.inprovide.com>,
>  Måns Rullgård <mru@inprovide.com> wrote:
> 
>
> Not necessarily.  That seems to be the default on Linux and Mac OS X, but
> many of the Unix systems I've worked on use DEL as the default intr key.
> To change it to control-C, add "stty intr '^C'" to your login script.

If the OP had such a system, he wouldn't be using ctrl-c to stop his
program.

--
Måns Rullgård
mru@inprovide.com

Report this thread to moderator Post Follow-up to this message
Old Post
Måns Rullgård
12-15-04 02:01 AM


Re: Getting main loop to recognize escap key?
On Tue, 14 Dec 2004 21:51:41 +0100, Måns Rullgård <mru@inprovide.com> wrote:

>James Johnson <jjjhnson2-1779231@yahoo.com> writes:
> 
>
>man sigaction
>
>Ctrl-C generates a SIGINT.

I got control-c to work great using SIGINT. But I'm still wondering if you c
an get a unix C main loop to wake up on hitting a key on the keyboard?

Jim


Report this thread to moderator Post Follow-up to this message
Old Post
James Johnson
12-15-04 08:59 PM


Re: Getting main loop to recognize escap key?
James Johnson <jjjhnson2-1779231@yahoo.com> writes:

> On Tue, 14 Dec 2004 21:51:41 +0100, Måns Rullgård <mru@inprovide.com> wrot
e:
> 
>
> I got control-c to work great using SIGINT. But I'm still wondering
> if you can get a unix C main loop to wake up on hitting a key on the
> keyboard?

Sure, just twiddle the mode of your tty properly, and use select().

--
Måns Rullgård
mru@inprovide.com

Report this thread to moderator Post Follow-up to this message
Old Post
Måns Rullgård
12-15-04 08:59 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Unix Programming archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 07:45 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.