mirror of
https://github.com/duanhf2012/origin.git
synced 2026-02-04 06:54:45 +08:00
26 lines
398 B
Go
26 lines
398 B
Go
package sysprocess
|
|
|
|
import (
|
|
"github.com/shirou/gopsutil/process"
|
|
"os"
|
|
)
|
|
|
|
func GetProcessNameByPID(pid int32) (string, error) {
|
|
proc, err := process.NewProcess(pid)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
processName, err := proc.Name()
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return processName, nil
|
|
}
|
|
|
|
func GetMyProcessName() (string, error) {
|
|
return GetProcessNameByPID(int32(os.Getpid()))
|
|
}
|
|
|