c#中的System.Diagnostics.Process和c++中的CreateProcess()哪个是最好的选择
System.Diagnostics.Process in c# and CreateProcess() in c++ which one is the best choice?
当我想在我的应用程序(c#)中启动子进程时,c#中的System.Diagnostics.Process
和c++中的CreateProcess()
哪一个是更好的选择?
给subProcess参数隐藏子进程的窗口查看子流程的输出,如日志等
另外,我想为subProcess设置CPU数量和内存限制。
我想安全地杀死所有的子进程(不泄漏内存和一些)当用户停止父进程
System.Diagnostics.Process
比较好。始终从托管代码调用托管代码方法。
我猜System.Diagnostics.Process将是一个很好的选择,因为您的应用程序是管理的。如果不想隐藏子进程,请不要设置:
the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
the_StartInfo.UseShellExecute = false;
要限制内核的数量,您必须尝试使用ProcessThread.ProcessorAffinity
using System;
using System.Diagnostics;
namespace ProcessThreadIdealProcessor
{
class Program
{
static void Main(string[] args)
{
// Make sure there is an instance of notepad running.
Process[] notepads = Process.GetProcessesByName("notepad");
if (notepads.Length == 0)
Process.Start("notepad");
ProcessThreadCollection threads;
//Process[] notepads;
// Retrieve the Notepad processes.
notepads = Process.GetProcessesByName("Notepad");
// Get the ProcessThread collection for the first instance
threads = notepads[0].Threads;
// Set the properties on the first ProcessThread in the collection
threads[0].IdealProcessor = 0;
threads[0].ProcessorAffinity = (IntPtr)1;
}
}
}
要限制内存使用集Process.MaxWorkingSet
,它可以帮助您达到相关进程允许的最大工作集大小。
相关文章:
- C++选择排序算法中的逻辑错误
- 选择和修改嵌套向量中的条目的最佳实践
- 数数并选择 sqlite 中的前三名
- 使用 Gtkmm 以编程方式选择 Gtk::TextView 中的文本
- 在 Windows 上的C++中使用选择功能进行轮询
- 如何允许用户选择何时停止三列中的每一列的旋转
- 根据C++中的外部输入选择类
- 选择排序以查找未排序数组中的最大数字
- 使用指针选择长无符号变量中的数字
- 正在分析BoostSpirit中固定列表中的选择
- 有选择地禁用库中的死代码消除
- 如何修复列表视图中的错误?,封装控件时无法选择任何项
- 元数据操作失败LNK2022错误 (8013118D):重复类型中的布局信息不一致 (选择设备参数):(0x020002
- 我的选择排序代码是否存在导致它跳过数组中的元素的问题?
- VTK:尝试使用 vtkrubberbandpick&vtkHardwareSelector 选择区域中的可见单元格
- Qt C++根据组合框中的选择创建一个对象
- 正确复制 QTableView 中的选择(模型索引问题)
- 更改资源管理器窗口中的选择
- 如何限制QTableWidget中的选择
- 基于CListView的SDI应用程序中的选择更改事件