在 CMD.exe 中,“start sh.exe”创建一个占用 700 MB 内存的 conhost 进程

在 CMD.exe 中,“start sh.exe”创建一个占用 700 MB 内存的 conhost 进程

Git bash(sh.exe)本来占用的内存很少,但是当使用 CMDstart sh.exe命令启动时,它会创建一个占用 3-700 MB 内存的 conhost.exe 进程。

有趣的是,start cmd /k sh.exe它做了同样的事情,但它创建的 conhost 进程仅占用 8 MB。

为什么使用“start”命令启动 sh.exe 会创建占用更多内存的 conhost 进程?

答案1

好的,我都看了使用 WPA.exe 进行跟踪在显示高内存使用率的跟踪中,内存使用量来自于创建屏幕缓冲区DoCreateScreenBuffer

Line #, Process, Commit Stack, Address, Count, Impacting Size, Size
1, conhost.exe (10848), [Root], , 46, 800784384, 800833536
2, ,    |- ntdll.dll!RtlUserThreadStart, , 31, 800669696, 800673792
3, ,    |    kernel32.dll!BaseThreadInitThunk, , 31, 800669696, 800673792
4, ,    |    |- ConhostV2.dll!ConsoleIoThread, , 13, 800509952, 800509952
5, ,    |    |    ConhostV2.dll!ConsoleHandleConnectionRequest, , 13, 800509952, 800509952
6, ,    |    |    ConhostV2.dll!ConsoleAllocateConsole, , 13, 800509952, 800509952
7, ,    |    |    |- ConhostV2.dll!SetUpConsole, , 10, 800460800, 800460800
8, ,    |    |    |    |- ConhostV2.dll!AllocateConsole, , 7, 800432128, 800432128
9, ,    |    |    |    |    ConhostV2.dll!DoCreateScreenBuffer, , 7, 800432128, 800432128
10, ,   |    |    |    |    |- ConhostV2.dll!SCREEN_INFORMATION::CreateInstance, , 6, 800415744, 800415744
11, ,   |    |    |    |    |    ConhostV2.dll!TEXT_BUFFER_INFO::CreateInstance, , 6, 800415744, 800415744
12, ,   |    |    |    |    |    |- ConhostV2.dll!DBCS_SCREEN_BUFFER::CreateInstance, , 4, 599891968, 599891968
13, ,   |    |    |    |    |    |    ntdll.dll!RtlpAllocateHeapInternal, , 4, 599891968, 599891968
14, ,   |    |    |    |    |    |    ntdll.dll!RtlpAllocateHeap, , 4, 599891968, 599891968
15, ,   |    |    |    |    |    |    ntdll.dll!NtAllocateVirtualMemory, , 4, 599891968, 599891968
16, ,   |    |    |    |    |    |    ntoskrnl.exe!KiSystemServiceCopyEnd, , 4, 599891968, 599891968
17, ,   |    |    |    |    |    |    ntoskrnl.exe!NtAllocateVirtualMemory, , 4, 599891968, 599891968
18, ,   |    |    |    |    |    |    ntoskrnl.exe! ?? ::NNGAKEGL::`string', , 4, 599891968, 599891968

start cmd /k sh.exe一个没有进行内存分配。这里只打印了一些字符,只使用了 69kB。

Line #, Process, Commit Stack, Address, Count, Impacting Size, Size
7, conhost.exe (10072), [Root], , 2, 81920, 81920
8, ,   ntdll.dll!RtlUserThreadStart, , 2, 81920, 81920
9, ,   kernel32.dll!BaseThreadInitThunk, , 2, 81920, 81920
10, ,   |- ConhostV2.dll!ConsoleIoThread, , 1, 69632, 69632
11, ,   |    ConhostV2.dll!SrvWriteConsole, , 1, 69632, 69632
12, ,   |    ConhostV2.dll!DoSrvWriteConsole, , 1, 69632, 69632
13, ,   |    ConhostV2.dll!DoWriteConsole, , 1, 69632, 69632
14, ,   |    ConhostV2.dll!WriteChars, , 1, 69632, 69632
15, ,   |    ConhostV2.dll!WriteCharsLegacy, , 1, 69632, 69632
16, ,   |    ConhostV2.dll!WriteRegionToScreen, , 1, 69632, 69632
17, ,   |    ConhostV2.dll!ConsolePolyTextOut, , 1, 69632, 69632
18, ,   |    ntdll.dll!RtlpAllocateHeapInternal, , 1, 69632, 69632
19, ,   |    ntdll.dll!RtlpAllocateHeap, , 1, 69632, 69632
20, ,   |    ntdll.dll!RtlpCommitBlock, , 1, 69632, 69632
21, ,   |    ntdll.dll!NtAllocateVirtualMemory, , 1, 69632, 69632
22, ,   |    ntoskrnl.exe!KiSystemServiceCopyEnd, , 1, 69632, 69632
23, ,   |    ntoskrnl.exe!NtAllocateVirtualMemory, , 1, 69632, 69632
24, ,   |    ntoskrnl.exe! ?? ::NNGAKEGL::`string', , 1, 69632, 69632
25, ,   |  , 0x2a657431000, 1, 69632, 69632

但我不知道为什么会发生这种情况。始终使用 start cmd /k 运行它。

相关内容