java 输入类名获取父类名

java 输入类名获取父类名,第1张

java中是可以多继承的,所以子类获得父类的类名,可以使用getSuperClass()这个方法来获得,示例如下:

public class Test1 extends Date {

public static void main(String[] args) {

new Test1()test();//测试获得父类类名方法

}

public void test() {

Systemoutprintln(Test1classgetSuperclass()getName());//打印父类类名,使用getSuperclass()方法

}

}

)可以查看进程的各项基本信息 如cpu 内存 父进程 执行路径 创建者等

)可以中止进程 创建新进程

)可以配置目标进程 配置刷新速度

最终效果图

(以下给出部分代码 其余像进程的创建 中止等 使用process类将很容易实现)

)使用wmi获取父进程id 进程创建者

(注意 使用wmi获得的内容 不宜循环刷新 这样代价比较大)

添加命名空间

Imports System Management

Public Class HandleObjectReady

Private plete As Boolean = false

Private obj As ManagementBaseObject

Public ReadOnly Property Complete As Boolean

Get

Return plete

End Get

End Property

Public ReadOnly Property Obj As ManagementBaseObject

Get

Return obj

End Get

End Property

Public Sub Done(ByVal sender As Object ByVal e As ObjectReadyEventArgs)

plete = true

obj = e NewObject

End Sub

End Class

Private Sub FillDetailUseWmi(ByVal pID As Integer)

Dim searcher As ManagementObjectSearcher = New ManagementObjectSearcher(( Select From Win _Process Where ProcessID= + pID))

Dim moc As ManagementObjectCollection = searcher Get

Dim observer As ManagementOperationObserver = New ManagementOperationObserver

Dim hor As HandleObjectReady = New HandleObjectReady

AddHandler observer ObjectReady AddressOf hor Done

For Each mo As ManagementObject In moc

mo InvokeMethod(observer GetOwner Nothing)

While Not hor Complete

System Threading Thread Sleep( )

End While

Dim user As String =

(hor Obj( returnValue ) ToString = )

user = hor Obj Properties( User ) Value ToString

If Not Me mDict ContainsKey(pID) ThenReturn

End If

If ((Not (mo( ParentProcessID )) Is Nothing)  _

AndAlso Me mDict ContainsKey(Convert ToInt (mo( ParentProcessID )))) Then

Me mDict(pID) ParentProce = Me mDict(Convert ToInt (mo( ParentProcessID ))) ProceName

End If

Me mDict(pID) Creator = user

If (Not (Me HandleDetailList) Is Nothing) Then

Me HandleDetailList(Me mDict(pID))

End If

Next

searcher Dispose

searcher = Nothing

moc Dispose

moc = Nothing

observer = Nothing

hor = Nothing

End Sub

)使用性能计数器计算cpu利用率

)计算过程

//通过计数器获取idle空闲进程cpu占用率r

//通过process类的TotalProcessorTime属性获取各进程的cpu时间 求和 得各进程(除空闲进程idle 该进程无法通过process类获得cpu时间)cpu时间和t

//通过t /( r )得到总cpu时间t

//对各进程 通过TotalProcessorTime获得进程cpu时间tnew 计算

(Tnew told)/t 即得该进程的cpu占用率 其中told是程序中记录的该进程上一次的TotalProcessorTime

)关于性能计数器

)关于性能计数器

系统会为每个进程分配一个计数器 通过new PerformanceCounter( Process % Processor Time 进程名称 )实例化该计数器 使用计数器对象的NextValue方法可以得到进程占用cpu的百分比

(第一次调用NextValue获取的值都为 之后就没问题了 这个要注意)

)Idle进程的含义

Idle意为懒散的 无所事事 事实上 idle不能算著一个进程 它用于表示cpu空闲资源 它所占的比率越高 表示你的机器越空闲

)多核CPU或使用超线程技术的CPU

对于多核或使用超线程技术的cpu 根据计数器求得的idle进程cpu占用比率将超过 % 此时应将idle的cpu利用率/总的cpu利用率 所得作为真正的idle的cpu利用率

添加命名空间

Imports System Diagnostics

Dim mIdle As PerformanceCounter = New PerformanceCounter( Process % Processor Time Idle )

Dim mTotal As PerformanceCounter = New PerformanceCounter( Process % Processor Time _Total )

Private Sub FillNeedRefreshInfo(ParamArray ByVal pCurrentAll() As Process)

Me mCurrentTotalCpuTime = Me CalCurrentTotalCpuTime

Dim i As Integer =

Do While (i < pCurrentAll Length)

If (pCurrentAll(i) Id = ) Then

Me mDict(pCurrentAll(i) Id) CpuPercent = Me mIdleCpuPercent

Else

Try Dim ms As Long = CType(pCurrentAll(i) TotalProcessorTime TotalMilliseconds Long)

Dim d As Double = ((ms Me mDict(pCurrentAll(i) Id) OldCpuTime) _

&( / Me mCurrentTotalCpuTime))

Me mDict(pCurrentAll(i) Id) CpuPercent = d

Me mDict(pCurrentAll(i) Id) OldCpuTime = ms

Catch  As System Exception

End Try

End If

If (Not (Me HandleProceRefresh) Is Nothing) Then

Me HandleProceRefresh(Me mDict(pCurrentAll(i) Id) ( Me mIdleCpuPercent))

End If

i = (i + )

Loop

End Sub

Private Function CalCurrentTotalCpuTime() As Double

Dim d As Double =

Dim idlePercent As Double = mIdle NextValue

Dim totalPercent As Double = mTotal NextValue

If (totalPercent = ) Then

Me mIdleCpuPercent =

Else

Me mIdleCpuPercent = (idlePercent ( / totalPercent))

End If

For Each p As Process In Me mCurrentAll

If ((p Id = )  _

OrElse p HasExited) Then

TODO Warning!!! continue If

End If

If ((Me mDict Is Nothing)  _

OrElse Not Me mDict ContainsKey(p Id)) Then

d = (d + p TotalProcessorTime TotalMilliseconds)

Else

d = (d  _

+ (p TotalProcessorTime TotalMilliseconds Me mDict(p Id) OldCpuTime))

End If

Next

Return (d / ( mIdleCpuPercent))

lishixinzhi/Article/program/net/201311/12462

版本 2

子程序 _按钮1_被单击

局部变量 本进程ID, 整数型

局部变量 比较进程ID, 整数型

本进程ID = 取进程ID (取执行文件名 ())

比较进程ID = 取进程ID (“explorerexe”)

判断开始 (本进程ID = 比较进程ID)

信息框 (“相同”, 0, )

默认

信息框 (“不相同”, #错误图标, )

版本 2

子程序 取进程ID, 整数型, 公开, 取指定进程的进程ID(返回第一个进程ID,失败返回0)

参数 进程名, 文本型, , 区分大小写

局部变量 临时信息, 进程信息_

局部变量 进程句柄, 整数型

局部变量 进程快照, 整数型

进程快照 = _创建快照 (2, 0)

如果真 (进程快照 ≠ 0)

临时信息dwSize = 296

进程句柄 = _第一个 (进程快照, 临时信息)

判断循环首 (进程句柄 ≠ 0)

如果真 (StrCmpNI_1 (进程名, 临时信息进程名称, _取文本长度 (进程名)) = 0) ' 比较进程名

_关闭对象 (进程快照)

返回 (临时信息进程ID)

如果真结束

进程句柄 = _下一个 (进程快照, 临时信息)

判断循环尾 ()

_关闭对象 (进程快照)

如果真结束

返回 (0)

以上就是关于java 输入类名获取父类名全部的内容,包括:java 输入类名获取父类名、VB.Net实现进程监视器的方法、易语言检测程序的父进程是不是explorer等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/10056606.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-04
下一篇2023-05-04

发表评论

登录后才能评论

评论列表(0条)

    保存