Score:0

Computer got stuck on infinite loop in a programme

us flag

I am using ubuntu 20.04. When there is an infinite loop in my c++ code computer is becoming stuck.What is the solution?

ChanganAuto avatar
us flag
We don't know your code.
Muhammed Sinan C K avatar
us flag
actually like while(1){} will make computer stuck and i have to restart it again .
Doug Smythies avatar
gn flag
you can kill your program. Say your program was called `infinite`, then in another terminal run `killall infinite` .
Muhammed Sinan C K avatar
us flag
But i heard from my friends that computer should automatically terminate it. Is there any way. Because i am unable to open terminal when it become stuck.
hr flag
If it's running in the shell foreground, you can try suspending it (Ctrl+Z) then killing it via the PID or %jobspec
David avatar
cn flag
Computers are not magic nor can the read minds the program is doing what you told it to do.
raj avatar
cn flag
raj
Infinite loop in your code definitely should not make the whole computer stuck. This would be the case long ago in DOS ;), that could run only one program at a time. Linux is (and always was) a **multiprocess** operating system (like all recent OS-es) which means many programs can run simultaneously. It's only your program that is stuck, but you can open another session and kill your program. (cont.)
raj avatar
cn flag
raj
You say you can't open terminal when your program is stuck - how did you try to open the terminal? In GUI, Ctrl+Alt+T or opening new window from the terminal window menu should work; if you're connected via ssh, just start a new ssh session. If you are at the physical text console of your computer, Alt+F1 through Alt+F6 keys should switch you to different terminals. There always should be a way. Please give us more details.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.