Print process name and cpu usage of that specific process

This commit is contained in:
Babak Farrokhi 2019-05-07 15:37:53 +02:00
parent 8bb7a68704
commit 12101674d5
Signed by: farrokhi
GPG Key ID: 6B267AD85D632E9A

View File

@ -16,6 +16,7 @@ func main() {
p, _ := process.NewProcess(int32(*flagPID))
v, err := p.Times()
name, _ := p.Name()
cnt := 0
for {
@ -24,7 +25,9 @@ func main() {
}
if err == nil {
fmt.Printf("%d pid: %d user: %f\t system: %f\n", time.Now().Unix(), *flagPID, v.User, v.System)
cpuUsage, _ := p.CPUPercent()
fmt.Printf("%d %s pid: %d cpu: %0.2f%%\t user: %0.2f\t system: %0.2f\n",
time.Now().Unix(), name, *flagPID, cpuUsage, v.User, v.System)
} else {
fmt.Println(err)
}