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
"
));
}
}
}
查看全文
相关阅读:
vue 点击出现下拉菜单,点击下拉菜单以外都要关闭菜单
关于SET ANSI_PADDING的用法
VUE中的/deep/用法
VUE中的/deep/用法
数字与字符串系列教材 (十)- 自己开发一个Java StringBuffer
数字与字符串系列教材 (九)- Java StringBuffer常见方法
数字与字符串系列教材 (八)- Java 比较字符串详解
数字与字符串系列教材 (七)- Java常见字符串方法
数字与字符串系列教材 (六)- Java中的字符串String详解
数字与字符串系列教材 (六)- Java中的字符串String详解
原文地址:https://www.cnblogs.com/juqiang/p/51322.html
最新文章
CodeFrist基础_迁移更新数据
CodeFrist基础_Fluent Api
CodeFrist基础
英语学习
简单的限流RateLimiter
redis实现简单的分布式锁
ERR wrong number of arguments for 'set' command
xACxEDx00x05tx00x0redis存key出现
浅谈Lock
setDaemon详解
热门文章
redis面试题,求求你别再问我redis了
JVM面试题,求求你别再问我java虚拟机了
idea新增文件版本提醒
Error:svn: E155038: Can't revert 'zuul' without reverting parent
JS-中使用Math.round(x)保留1位小数点
JS 中Math.ceil()、Math.floor()和Math.round()的区别
JS 中Math.ceil()、Math.floor()和Math.round()的区别
vue基本使用--refs获取组件或元素
vue基本使用--refs获取组件或元素
vue 点击出现下拉菜单,点击下拉菜单以外都要关闭菜单
Copyright © 2011-2022 走看看