How to close an infinite loop in c++ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to close an infinite loop in c++

C++

19th Oct 2018, 1:45 AM
Subhrajit
Subhrajit - avatar
3 Answers
+ 4
It depends on where the program is running. In SoloLearn playground, the server exits the program after it hits a time limit so you don't need to worry about it. Some systems give you a character you type to abort the program. I've built systems where my task manager detected a task that failed to return to its top level loop.
19th Oct 2018, 2:12 AM
John Wells
John Wells - avatar
+ 3
Windows: Ctrl-Break : instantly sends an IRQ (Interrupt ReQuest) Ctrl-C : but requires the keyboard to be read in some way Linux, Apple, Android: Ctrl-Break (if available; try Fn+Esc for OSX) Ctrl-C (SIGTERM -inate) Ctrl-Z (SIGHUP : hangup) Ctrl-\ (SIGQUIT) Notes: On PC's the "break" key is usually combined with the "pause" key, at the upper right corner. SIGHUP only "backgrounds" the foreground process (it's still there) but you usually get a shell so you can use "ps" to find your process and "kill" it with a signal. You may need to press Enter to update the display after some of these key combos. Should you see this advice elsewhere: Kill-by-task-manager (in general, not special stuff like John Wells'), kill -9 (SIGKILL) and SIGSTOP should only be used as a last resort for a hung process; they're dirty kills.
19th Oct 2018, 3:18 AM
Kirk Schafer
Kirk Schafer - avatar
0
no I asked how to come out of the program once an infinite loop begins…
19th Oct 2018, 2:01 AM
Subhrajit
Subhrajit - avatar