zoukankan
html css js c++ java
一个简单的进程察看器
using
System;
using
System.Diagnostics;
namespace
ProcessManager
{
/**/
///
<summary>
///
Summary description for Class1.
///
</summary>
class
MainEntry
{
/**/
///
<summary>
///
The main entry point for the application.
///
</summary>
[STAThread]
static
void
Main(
string
[] args)
{
if
(args.Length
<
1
)ListProcesses();
else
if
(args[
0
].Length
>
0
)ListProcess(args[
0
]);
}
private
static
void
ListProcesses()
{
string
output
=
""
;
int
limit
=
36
;
Console.WriteLine(
"
PID
"
.PadRight(
6
)
+
"
Name
"
.PadRight(
16
)
+
"
Memory
"
.PadLeft(
10
)
+
"
VM size
"
.PadLeft(
10
)
+
"
Threads count
"
.PadLeft(
20
));
Console.WriteLine(
"
-
"
.PadRight(limit
+
34
,
'
-
'
));
foreach
(Process proc
in
Process.GetProcesses())
{
string
pid
=
proc.Id.ToString();
string
pname
=
proc.ProcessName;
string
pcount
=
proc.Threads.Count.ToString();
string
pmemsize
=
(proc.PeakWorkingSet
/
1024
).ToString()
+
"
K
"
;
string
pvmsize
=
(proc.PeakPagedMemorySize
/
1024
).ToString()
+
"
K
"
;
output
=
String.Format(
"
{0}{1}{2}{3}{4}
"
,pid.PadRight(
6
),pname.PadRight(
16
),pmemsize.PadLeft(
10
),pvmsize.PadLeft(
10
),pcount.PadLeft(
10
));
Console.WriteLine(output);
}
}
private
static
void
ListProcess(
string
processid)
{
int
pid
=
-
1
;
try
{
pid
=
Convert.ToInt32(processid);
}
catch
{
}
if
(
-
1
==
pid)
{
Console.WriteLine(
"
Invalid processID!
"
);
return
;
}
string
output
=
""
;
Process proc
=
null
;
try
{
proc
=
Process.GetProcessById(pid);
}
catch
{
}
if
(
null
==
proc)
{
Console.WriteLine(
"
Invalid processID!
"
);
return
;
}
Console.WriteLine(
"
PID:
"
+
proc.Id.ToString());
Console.WriteLine(
"
-
"
.PadRight(
50
,
'
-
'
));
//
Console.WriteLine("Main Module");
//
Console.WriteLine("-".PadRight(50,'-'));
Console.WriteLine(
"
Module Name
"
.PadRight(
50
)
+
"
Memory Size
"
);
WriteModuleInformation(proc.MainModule);
Console.WriteLine(
"
-
"
.PadRight(
50
,
'
-
'
));
//
Console.WriteLine("All Modules");
//
Console.WriteLine("-".PadRight(50,'-'));
Console.WriteLine(
"
Module Name
"
.PadRight(
50
)
+
"
Memory Size
"
);
foreach
(ProcessModule pm
in
proc.Modules)WriteModuleInformation(pm);
Console.WriteLine(
"
-
"
.PadRight(
50
,
'
-
'
));
Console.WriteLine(
"
Thread List:
"
);
Console.WriteLine(
"
-
"
.PadRight(
50
,
'
-
'
));
Console.WriteLine(
"
ID
"
.PadRight(
6
)
+
"
Thread State
"
.PadRight(
20
)
+
"
Total Processor Time
"
);
Console.WriteLine(
"
-
"
.PadRight(
50
,
'
-
'
));
foreach
(ProcessThread pt
in
proc.Threads)
{
output
=
String.Format(
"
{0}{1}{2}
"
,pt.Id.ToString().PadRight(
6
),pt.ThreadState.ToString().PadRight(
20
),pt.TotalProcessorTime);
Console.WriteLine(output);
}
}
private
static
void
WriteModuleInformation(ProcessModule pm)
{
Console.WriteLine(String.Format(
"
{0}{1}
"
,pm.ModuleName.PadRight(
50
),(pm.ModuleMemorySize
/
1024
).ToString().PadLeft(
10
)
+
"
K
"
));
}
}
}
查看全文
相关阅读:
jQuery中的Deferred详解和使用
Windows Server 2003 无法布署.NET Framework4.5 应用解决方案
jquery 获取父窗口的元素、父窗口、子窗口
Android USB HOST API
ASP.NET MVC+Vue.js实现联系人管理
Vue在ASP.NET MVC中的进行前后端的交互
JS中 “is not defined” 如何判断defined,defined和undefined 的区别
Android自定义view实现个人中心设置界面带点击事件
java 正则表达式(内附例子)
在asp.net mvc 中使用Autofac
原文地址:https://www.cnblogs.com/juqiang/p/51322.html
最新文章
验证证件类型
SQL表相关技巧
jQuery的下拉选select2插件用法
jquery-validation.js验证插件使用详解
C# Sql缓存依赖
使用WindowManager添加View——悬浮窗口的基本原理
Sql Server优化---统计信息维护策略
Android 带你彻底理解 Window 和 WindowManager
activity的android:name 设置问题
Android Back Home键监听
热门文章
android实现程序开机自启动
Android Java基本知识
翻译Android USB HOST API
AsyncTask execute 为单一模式 executeOnExecutor 可以为并发模式
让Activity更加简洁第(二)篇---AsyncTask的使用姿势
无法访问windows installer服务怎么办
SQL Server 收缩日志
线程池之ThreadPool类与辅助线程
win10 C盘清理垃圾
jQuery的deferred对象详解
Copyright © 2011-2022 走看看