26

Does anyone come across a scenario when the command prompt is running a process and then it gets stuck and the process is also sleeping. Then when we press Enter key in the cmd window the process continues.

Is there any way to avoid this? or can this be handled??

phuclv
  • 37,963
  • 15
  • 156
  • 475
Sangram Mohite
  • 735
  • 4
  • 11
  • 23

3 Answers3

29

The other answers are wrong! The Windows console has a separate mode called "mark mode" for selecting text. In that mode the screen will be frozen, texts will go into the buffer and if the buffer is full the running process will be blocked

Mark mode

If quick edit mode is enabled (by default it's disabled in older Windows but enabled in Windows 10) then clicking inside the console window will activate mark mode and result in what you observed

It's very easy to accidentally click the console and stop the command. When you press Enter or Esc the selected text will be copied to clipboard and mark mode will be exited, therefore the process will run again. Priority is absolutely irrelevant here because if the buffer is full then the process is blocked forever until you exit mark mode, regardless of the priority. The console does nothing to change the priority when there are some inputs. Try opening an app that outputs a lot of data in the highest priority and click the console, the app will still be blocked indefinitely even if the CPU is in idle

Here's an example of QuickEdit mode setting in Windows 8 console:

cmd

To fix this you can disable QuickEdit mode if you don't need it. In this case copying will be more troublesome because you must open the context menu, select Edit > Mark. You can also disable QuickEdit mode by setting ENABLE_QUICK_EDIT_MODE with SetConsoleMode() if you're writing your own console application

See also

phuclv
  • 37,963
  • 15
  • 156
  • 475
  • This is correct! I have been running in to this problem running processes with Powershell. Unchecking QuickEdit and Insert Mode fixed the problem for me. – Darren Apr 07 '21 at 20:38
2

If other processes are sucking all the cycles and have a higher prio, then your process might be stopped. A user input might just give it a prio boost, so it starts again. See Microsoft Docs at https://learn.microsoft.com/en-us/windows/win32/procthread/priority-boosts for more information.

cxxl
  • 4,939
  • 3
  • 31
  • 52
  • there's no prio boost when you give input to an application – phuclv Sep 27 '20 at 00:24
  • @phuclv: According to https://learn.microsoft.com/en-us/windows/win32/procthread/priority-boosts there is. – cxxl Sep 28 '20 at 06:25
  • The case where all inputs are stuck due to high CPU usage from other processes is extremely rare. And please read the OP's note: ***and the process is also sleeping***. The process can't be sleeping just because other processes are using more CPUs, it can only be preempted and not blocked – phuclv Sep 28 '20 at 06:29
1

It happened to me today while executing a batch file that includes TFSBuild. I already received email notification from TFSBuild that it is successful, but somehow the batch file did not proceed to the next line.

I waited 1 hour. I pressed Enter, Mark for Edit etc. but none of that worked. Then I hit Ctrl+C to try to terminate the batch file. When asked if I want to terminate, i entered N. Weirdly enough, the batch file continued after that.

remondo
  • 318
  • 2
  • 7