- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- C breaking infinite loop by <ESC> or <F10>
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-15-2002 10:56 PM
тАО08-15-2002 10:56 PM
C breaking infinite loop by <ESC> or <F10>
Is someone had an C program example to break an inifinite loop by pressing ESCAPE or F10 keyboard key ?
M.Piguel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-15-2002 11:24 PM
тАО08-15-2002 11:24 PM
Re: C breaking infinite loop by <ESC> or <F10>
Hi,Hi,
I am not quite sure what you are after, but
I assume the following:
. You have a program that is designed to run in
an infinite loop.
. For some reason you want to have the possibility
to exit this loop but not exit the program.
I can think of at least two ways to do this:
1, Use a select call in the loop to notice when some
input is given, test what input was given and act
accordingly.
2, Set up a signal-handler to cacth a signal SIGUSR2
which you may send to the prosess using the kill command
or a small program.
Regards
Olav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-15-2002 11:48 PM
тАО08-15-2002 11:48 PM
Re: C breaking infinite loop by <ESC> or <F10>
Try to understand the 'catch_sigint()' funtion as mentioned in http://www.arcterex.net/c_notes.html
Succes,
Ceesjan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-16-2002 01:49 AM
тАО08-16-2002 01:49 AM
Re: C breaking infinite loop by <ESC> or <F10>
Thanks for these first elements of answer, but I had already found these examples. My problems are:
1. which code is sent when I press
2. all examples speak about SIGINT, SIGABRT and so on but never about others signals.
3. how may I use SIGUSR1 (or SIGUSR2) or write a program which interact when I press a key of my keyboard ?
Regards
Michel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-16-2002 02:39 AM
тАО08-16-2002 02:39 AM
Re: C breaking infinite loop by <ESC> or <F10>
I think that what code is sent when you press
the smallest problem.
What you must consider is how your program will notice that you
press anything at all. Unless you want to use signals you will
have do a read inside the loop. The problem then is that if you
do a read when there is no data entered your read will hang there
and block the execution of the loop.
That is why I mentioned the select() call that may be used to
test if there is something there to read.
Se the man page for select for examples on how this function
may be called from a program.
man select
Regards
Olav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-16-2002 04:03 AM
тАО08-16-2002 04:03 AM
Re: C breaking infinite loop by <ESC> or <F10>
in addition to what the others wrote, you will have to use "curses", to enable your program to understand the encoding of the function keys, in dependence of the environment variable "$TERM"...
The ESCAPE key is easy (code number decimal 27), but the function keys can send from one to many characters PER KEY PRESSED, so that part is a little bit more difficult.
Reading about the library "curses" might help you there.
HTH,
Wodisch
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-16-2002 06:03 AM
тАО08-16-2002 06:03 AM
Re: C breaking infinite loop by <ESC> or <F10>
The better way to do this is to let your loop run as fast as possible and to set up a signal handler. You could change the interrupt, kill, or quit keys to whatever you like and then build a signal handler to deal with SIGINT, SIGKILL, or SIGQUIT. If you want to do it at the really low-level use signal,setjmp, and longjmp. Man signal, setjmp, and longjmp for details. By the way, using ESC is generally a bad idea because so many keys generate ESCAPES as part od their sequence.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-16-2002 06:28 AM
тАО08-16-2002 06:28 AM
Re: C breaking infinite loop by <ESC> or <F10>
I've understood it's really better to use interrupt signal like SIGINT etc...
I've made a test and
Where can I find some examples to catch these signals ?
Regards
Michel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-16-2002 06:53 AM
тАО08-16-2002 06:53 AM
Re: C breaking infinite loop by <ESC> or <F10>
Note that when you use a signal handling function do as little as possible and in most cases you need to reset the handler to itself.
This should get you started but if you need a more complex example using setjmp and longjmp to do a non-local goto then that's about a three-minute bit of coding.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-16-2002 07:35 AM
тАО08-16-2002 07:35 AM
Re: C breaking infinite loop by <ESC> or <F10>
By default
This is not as easy as it sounds, because most terminals do not map all signals. So, dont confuse SIGKILL to be the same as
Regards,
Shannon