1

I have a c++ program that performs some very long-running tasks (3-level deep loop with genetic algorithm inside - about 2 hours needed to complete on my CPU). I'd like to run the program (compiled on MS Visual Studio 2019) and don't monitor it constantly but unfortunately, it freezes after some time (20-30 minutes, sometimes less). No calculations are processed since then (I can see it both on the console screen where some output should appear every 2 minutes and on Windows Task Manager when CPU usage suddenly drops). There is no message, no 'shadow window' or anything. To resume program I have to manually press "enter" key in the console and it resumes its work.

I did not find any questions like that here on StackOverflow or anywhere else. I kind of predict that this is Windows behavior to save resources from possibly unused processes, but in my case, I would like to disable this behavior and let the program run from start to the end.

contrl
  • 109
  • 1
  • 7
  • 2
    If your application uses threads it might be an indication of a dead lock. – vahancho Jul 20 '20 at 11:18
  • If it's windows powershell, try not to edit text (or select) as it will interrupt the execution and resumes on un-selection) – PirklW Jul 20 '20 at 11:19
  • @vahancho it does not, everything is in main thread, starts from main() function – contrl Jul 20 '20 at 11:19
  • @PirklW well it starts in standard windows console and I don't edit text or do anything, just minimize the window – contrl Jul 20 '20 at 11:21
  • 1
    Probably you guessed it right. Windows might suspend apps to save resources. Not sure it it applies to non-UWP apps as well, but you can try disabling it from suspending automatically, check https://answers.microsoft.com/en-us/windows/forum/windows_10-other_settings/apps-suspended-in-task-manager/60cbdc88-4d61-4809-b752-2f3148a2ea0b – Debargha Roy Jul 20 '20 at 11:22
  • There are, unfortunately, infinite number of reasons why a process might get stuck, seemingly doing nothing. On Linux I would attach `gdb` to the running process and inspect its current state. Perhaps Windows offers an equivalent debugging tool. – Sam Varshavchik Jul 20 '20 at 12:06
  • @contrl Can you confirm that this is not an issue: https://stackoverflow.com/questions/33883530/why-is-my-command-prompt-freezing-on-windows-10. Also, can you clarify if this happens with any code, or just with some specific one. If it is about specific code, then please provide us a minimum reproducible example. – brc-dd Jul 20 '20 at 18:06
  • Since you compile it by VS2019, while the prgram freezes, you can attach VS2019 to the process to check what happened. – grizzlybears Jul 21 '20 at 02:04
  • 1
    @brc-dd great catch, it was actually my issue. I've noticed that there is no indication of suspended process (like the green label in task manager) as it was shown at thread mention by Debargha here in comments. So probably CPU usage drop was just a coincidence and true issue was with printing output in the console. After changing code to print messages continuously every few seconds issue was resolved. – contrl Jul 23 '20 at 15:35

0 Answers0