服务启动的进程无法分配内存

发布于 2024-12-06 01:47:04 字数 666 浏览 0 评论 0原文

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

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

该机器运行的是Windows XP SP3。它没有超出提交费用,约为物理 RAM 的 80%。

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

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

编辑:

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

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

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.

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.

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.

EDIT:

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.

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

塔塔猫 2024-12-13 01:47:04

我希望这个答案能对将来的人有所帮助......
我遇到了同样的问题 - 如果允许窗口渲染,应用程序可以正常运行,但如果在服务下运行并且不允许与桌面交互,则启动时会崩溃。解决方案在于增加注册表中非交互式 Windows Station 堆的大小,在我的计算机上将其设置为 512KB,而交互式 Windows Station 堆为 3072KB。

您可以通过转到

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

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

SharedSection=1024,3072,512

第二个数字是交互式 Windows Station 堆的大小,最后一个数字是大小非交互式 Windows 工作站堆。如果删除最后一个数字,则交互式和非交互式 Windows Station 堆的大小将相同。我就是这么做的。

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

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.

You can change this by going to

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

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

SharedSection=1024,3072,512

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.

Read the details here: http://support.microsoft.com/kb/184802

过期情话 2024-12-13 01:47:04

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

作业对象可用于限制进程(或进程组)的内存使用,但需要将相关进程与该作业对象关联起来。

服务流程没有这样的作业对象。

考虑使用注册表来允许您从受影响的进程启动时进行调试: http://msdn.microsoft.com/en-us/library/a329t4ed.aspx

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??

Job objects can be used to restrict the memory usage of a process (or group of processes), but something would need to associate the processes in question with that job object.

There is no such job object for service processes.

Consider using the registry to allow you to debug from the start-up of the affected processes: http://msdn.microsoft.com/en-us/library/a329t4ed.aspx

墨小墨 2024-12-13 01:47:04

您可能会发现 SysInterals Procmon 对于查看进程的运行情况很有用。

You might find SysInterals Procmon useful for seeing what's going on with your processes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文