可以在Powershell脚本中以%或兆字节为单位设置最大内存消耗吗? [英] Possible to set a maximum of memory consumption on a powershell script in % or megabyte?

查看:212
本文介绍了可以在Powershell脚本中以%或兆字节为单位设置最大内存消耗吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时我的脚本会耗尽所有内存.由于我不想一直监视它们,也不想手动将cpu优先级设置为低,所以我想知道是否可以为该特定脚本提供一个内存值(也许以mb为单位). 这个选项存在吗?

I sometimes have scripts which are eating up all the memory. Since I don't want to monitor them all the time or set cpu priority to low manually I am wondering if there is an option to give that specific script a value (maybe in mb) of memory. Does this option exist?

推荐答案

PowerShell不提供任何内置方式来控制系统资源,如脚本使用的内存.

PowerShell doesn't provide any built-in way to control system resources like the memory used by a script.

Windows确实提供了一种将系统资源限制为进程组的方法,您可以在此处了解更多信息:

Windows does provide a way to limit system resources to groups of processes, you can learn more about that here: http://msdn.microsoft.com/en-us/library/windows/desktop/ms684161(v=vs.85).aspx

如果您的脚本占用了太多内存,建议您调查内存泄漏.有许多工具可以帮助跟踪内存泄漏.有些是低级别的(例如,在windbg中使用SOS中的!dumpheap-

If your scripts are consuming too much memory, I'd suggest investigating the memory leak. There are many tools that help track memory leaks. Some are low level (e.g. using !dumpheap from SOS in windbg - http://msdn.microsoft.com/en-us/library/bb190764(v=vs.110).aspx). Others are pretty smart, letting you take multiple snapshots and show you just the newly allocated objects between the snapshots. You can search for ".Net memory profiler" to get an idea of what's available.

这篇关于可以在Powershell脚本中以%或兆字节为单位设置最大内存消耗吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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