服务启动的进程无法分配内存 [英] Processes launched by a service can't allocate memory

查看:75
本文介绍了服务启动的进程无法分配内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 C# 服务作为 LocalSystem 帐户运行,它根据需要启动许多其他进程.这几个月来一直很顺利.就在本周,一些子进程崩溃了.我给它们附加了一个远程调试器,但它们在内存分配中失败(C++ new 运算符返回 0x0),这是崩溃的间接原因.

I have a C# service running as the LocalSystem account which launches numerous other processes depending on what its needs are. This has been going fine for a few months. Just this week, some of the sub-processes are crashing. I've attached a remote debugger to them, and they're failing in memory allocations (C++ new operator returns 0x0), which is the indirect cause of the crash.

有趣的是,如果我 RDP 进入机器,我可以轻松地从 CMD 启动进程,没有问题.然而,当服务启动它时,就不行了.

Funny thing is, if I RDP into the machine, I can easily launch the process from CMD no problems. Yet when the service launches it, no go.

机器运行的是 Windows XP SP3.它不是在提交费用中大约是物理 RAM 的 80%.

The machine is running Windows XP SP3. It isn't out of the commit charge is about 80% of physical RAM.

服务可以使用多少进程或多少内存,包括该服务产生的进程,是否有一些特殊限制??

Are there some special limitations of how many processes or how much memory can be used by a service, including processes spawned by that service??

为什么这些进程无法分配内存的任何其他想法.

Any other ideas why these processes would be unable to allocate memory.

我已经很好地查看了来自 SysInternals 的 Procmon 崩溃场景,但它没有透露任何内容(我可以看到).看起来一切正常,然后突然崩溃.我可以通过附加远程调试器确认它在从 c++ 新调用中取消引用空指针后崩溃.这是应用程序中分配的第一个对象之一,它永远不会失败.

I've had a good look at the crashing scenario with Procmon from SysInternals, and it doesn't reveal anything (that I can see). It all looks like it's going normal, then suddenly crashes. I can confirm from attaching a remote debugger that it is crashing after dereferencing a null pointer from a c++ new call. This is one of the first objects allocated in the app, it should never fail.

我还发现,如果我启用服务选项:允许服务与桌面交互,那么所有子进程都会正确启动.但是,当您通过 RDP 连接时,do 会出现在桌面上,如果您通过 RDP = YUK 注销,则会不幸终止!不过,这仍然不是一个理想的解决方案 - 我真的很想知道为什么子进程在第 6 个子进程之后无法分配内存.

I also discovered that if I enable to services option: Allow services to interact with desktop, then all of the child processes launch correctly. The do, however, appear on the desktop when you connect via RDP and are unfortunately terminated if you log out via RDP = YUK! This still isn't an ideal solution, though - I'd really like to know why the child processes were unable to allocate memory after the 6th child process.

推荐答案

我希望这个答案能在未来对某人有所帮助...我有同样的问题 - 如果允许 Windows 呈现,应用程序会运行良好,但如果在服务下运行并且不允许与桌面交互,则会在启动时崩溃.解决方法是在注册表中增加非交互式windows station heap的大小,在我的机器上设置为512KB,而交互式windows station heap是3072KB.

I hope this answer will help somebody in the future... I had the same problem - apps would run fine if windows were allowed to render, but would crash on startup if ran under a service and not allowed to interact with desktop. The solution lies in increasing the size of non-interactive windows station heap in the registry, which was set to 512KB on my machine while interactive windows station heap was 3072KB.

您可以通过转到

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\SubSystems\Windows

该值是一个长字符串.您需要更改 SharedSection 设置,如下所示:

The value is a long string. You need to change the SharedSection setting which looks something like this:

SharedSection=1024,3072,512

SharedSection=1024,3072,512

第二个数字是 interactive windows station heap 的大小,最后一个是 non-interactive windows station heap 的大小.如果删除最后一个数字,则交互式和非交互式 Windows 站堆将具有相同的大小.这就是我所做的.

The second number is size of interactive windows station heap and the last one is size of non-interactive windows station heap. If you delete the last number then interactive and non-interactive windows station heaps will be of the same size. That's what I did.

在此处阅读详细信息:http://support.microsoft.com/kb/184802

这篇关于服务启动的进程无法分配内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆