On my Windows10 laptop, I run a simple USB camera snapshot program, commandcam.exe (from https://batchloaf.wordpress.com/commandcam/), in a console .cmd script, which has one line:
FOR /l %%i in (1,1,1000000) DO FOR /F "usebackq delims==" %%G IN (`c:systoolsdate "+%%Y%%m%%d-%%H%%M%%S"`) DO commandcam /devnum 2 /filename %%G.bmp /quiet & sleep 55
where date.exe and sleep.exe in my c:systools were downloaded from http://unxutils.sourceforge.net Basically, the commandcam program creates files like 20210911-113214.bmp and sleeps 55 seconds and repeats. But once every few hours to a few days, my script freezes, with a blinking cursor. (This is absolutely unrelated to the problem that you accidentally click somewhere in the console to put it in text select mode. Note: my cursor always blinks)
I extensively checked all messages in the event viewer corresponding to the time it started to freeze. Found none relevant. Checked all processes with a start time corresponding to that time with a sysinternals tool pslist. Found only one, which is a new cmd.exe shown below (pid 22264 here):
cmd.exe (pid 16364) conhost.exe cmd.exe (pid 22264) <-- this one started when my cmd script froze
I notice when my script works, the parent cmd (16364) spawns commandcam, which takes a camera shot and exits, then the cmd spawns sleep; there will not be a new cmd process. When I see this new cmd, the script freezes. In case it helps, here’s more info about this new cmd process:
pslist v1.28 - Sysinternals PsList Copyright ⌐ 2000-2004 Mark Russinovich Sysinternals Process and thread information for <my laptop>: Name Pid Pri Thd Hnd Priv CPU Time Elapsed Time cmd 22264 8 1 136 83040 0:00:00.046 4:24:07.933 VM WS Priv Priv Pk Faults NonP Page 4194303 6856 83040 84512 2561 11 133 Tid Pri Cswtch State User Time Kernel Time Elapsed Time 19500 9 94 Wait:UserReq 0:00:00.000 0:00:00.031 4:24:07.933
I notice that its private memory is kind of high (83040 KB). So I checked with Task Manager, which shows:
Mem active private ws 12K; private ws 12K; shared ws 6776K; Paged pool: 133K; NP pool: 11K; Handles: 136
There’s great difference between pslist and Windows’ Task Manager (only 12 KB). I think it’s because pslist shows virtual private memory while Task Manager shows working set.
I don’t know what else I can check. The "Wait:UserReq" process state is normal. By the way, I find that if I use Process Explorer and try to examine the thread call stack of this new cmd process, this process will be gone and commandcam will start, followed by sleep 55 seconds, … i.e. everything will be back to normal. I don’t know why. It’s like checking the thread stack triggers something and it breaks the hang.