system — 系统
import "gomaton.dev/sdk/system"
Package system 进程与 shell(胶水:shell + /proc)。
能力总览:
- Shell / ShellTimeout 执行任意 shell 命令(后者带毫秒超时)。
- 进程:Pid 按进程名/包名取 PID。
- 资源:CpuUsage 整机 CPU 占用、MemKB 某进程内存(KB)。
CpuUsage
func CpuUsage(pid int) float64
CpuUsage 进程 CPU 占用百分比(top 单次采样,解析随 ROM 有差异)。
MemKB
func MemKB(pid int) int
MemKB 进程物理内存 KB(/proc/<pid>/status VmRSS)。
Pid
func Pid(name string) int
Pid 按进程名/包名取 PID(第一个);没有返回 0。
Shell
func Shell(cmd string) string
Shell 执行一条 shell 命令(sh -c),返回合并输出。
ShellTimeout
func ShellTimeout(cmd string, timeoutMs int) (string, error)
ShellTimeout 带超时(毫秒)的 shell。