在Windows批处理文件结尾简单插入符号(^)消耗的所有内存 [英] Simple caret (^) at end of Windows batch file consumes all memory
问题描述
在相对较短的时间这个简单的批处理文件占用的Windows 7(x64)的所有可用内存。这是怎么回事?并可以采取什么样的precautions抵御反对呢?
This simple batch file in relatively short order consumes all available memory on Windows 7 (x64). What's going on? and what precautions can be taken to ward against it?
any-invalid-command-you-like-here ^
显然需要preconditions展示效果:
Apparently necessary preconditions to exhibit the effect:
- 插入符号
^
是文件中的最后一件事,脚本不换行终止 - 插入符号是由至少2个空格或字符,例如pceded $ P $如果下面再present空间内存泄漏不会被触发点
^
,而这一次将.. ^
(只是慢)
- the caret
^
is the very last thing in the file, and the script is not terminated with a newline - the caret is preceded by at least 2 spaces or characters, e.g. if the dots in the following represent spaces the memory leak will not be triggered
.^
, while this one will..^
(just slowly)
在此的的Process Explorer 的屏幕截图,该脚本已运行约30秒,消耗2.9GB,并以稳定的速度仍在攀升:
In this Process Explorer screen shot, the script had been running about 30 seconds, consumed 2.9GB, and was still climbing at a steady rate:
如果你打算用这个实验,确保您可以在关闭窗口[X]控制得到或有一个任务管理器或Process Explorer中解雇了,并准备为<大骨节病>按Ctrl-C 骨节病> <大骨节病>用CTRL-Break 骨节病>,的Alt-F4 骨节病> 没有任何效果
If you're going to experiment with this, make sure you can get at the Close Window [X] control or have a Task Manager or Process Explorer fired up and ready as Ctrl-C, Ctrl-Break, Alt-F4 have no effect.
这将会出现多个插入符会导致内存使用更快地斜坡上升。我第一次遇到这种没有足够的可用内存为1或2分钟做简单的事情,像<大骨节病>使用Alt-Tab 骨节病>甚至三指敬礼<大骨节病>按Ctrl-Alt-Del组合骨节病>是无效的。我只好硬实力关闭机器。
It appears multiple carets will cause the memory usage to ramp up much more quickly. The first time I encountered this there wasn't enough memory available in 1 or 2 minutes to do simple things like Alt-Tab and even the 3 finger salute Ctrl-Alt-Del was ineffective. I had to hard power off the machine.
推荐答案
这样做的原因(从我的理解)是由于CMD间preTER寻找一个字符逃脱因为 ^
是批处理转义字符。而不是正确识别在这种情况下文件 EOF
结束后,CMD只是不断循环和初始化的东西,而寻找逃跑的字符。
Thoughts
The cause of this (from my understanding) is due to the cmd interpreter looking for a character to escape since the ^
is the batch escape character. Instead of properly identifying the end of file eof
in this scenario, cmd just keeps looping and initializing something while looking for the character to escape.
与 CC ^^^
(用于加快泄漏多个克拉)。
Reproduced on Windows 8 Pro (64) with cc^^^
(Multiple carats used to speed up the leak).
CC ^
无限循环和泄漏速度很慢。
cc^
infinite loop and leaks very slowly.
CC ^^
崩溃与正常无效命令错误。
cc^^
crashes with normal invalid command error.
CC ^^^
无限循环和泄漏速度更快。
cc^^^
infinite loop and leaks faster.
CC ^
无限循环和泄漏速度很慢。
cc ^
infinite loop and leaks very slowly.
CC ^^
崩溃与正常无效命令错误。
cc ^^
crashes with normal invalid command error.
CC ^^^
无限循环和泄漏速度更快。
cc ^^^
infinite loop and leaks faster.
CC^
崩溃与正常无效命令错误。
cc"^
crashes with normal invalid command error.
CC^^
崩溃与正常无效命令错误。
cc"^^
crashes with normal invalid command error.
CC^^^
崩溃与正常无效命令错误。
cc"^^^
crashes with normal invalid command error.
- 只有无限循环和泄漏时,克拉
^
的字面意义(报价之外)。当报价添加脚本崩溃与标准的命令无效错误。 - 只有无限循环,当批处理文件是EN codeD为 UTF-8 或 ASCII 泄漏。当 UTF-16 ,脚本崩溃与标准的命令无效错误。
- 必须是奇数克拉为无法逃脱最后克拉。
- Only infinite loop and leaks when carats
^
are used literally (outside of quotations). When quotation added the script crashes with standard invalid command error. - Only infinite loop and leaks when batch file is encoded as UTF-8 or ASCII. When UTF-16, the script crashes with standard invalid command error.
- Must be an odd number of carats as to not escape the last carat.
- 确保没有批处理脚本以克拉
^
(0x5E)或至少奇数克拉的结束。 - 或EN code他们UTF-16。
- Make sure no batch scripts end with a carat
^
(0x5E) or at least an odd number of carats. - Or encode them in UTF-16.
这篇关于在Windows批处理文件结尾简单插入符号(^)消耗的所有内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!