diff --git a/modules/disk-load/cmd/disk-load/cpu_process.go b/modules/disk-load/cmd/disk-load/cpu_process.go index af6f722c..6c01251d 100644 --- a/modules/disk-load/cmd/disk-load/cpu_process.go +++ b/modules/disk-load/cmd/disk-load/cpu_process.go @@ -108,6 +108,8 @@ func (m *Machine) unitProcs(cgroup string) map[int]procReading { // they can carry a password. func (m *Machine) commandLine(pid int) string { s, _, _ := strings.Cut(m.read("/proc/"+strconv.Itoa(pid)+"/cmdline"), "\x00") + s, _, _ = strings.Cut(s, " ") // a process that rewrites its title puts its whole command line here + s, _, _ = strings.Cut(s, "\t") s = strings.TrimSpace(s) if r := []rune(s); len(r) > 120 { s = string(r[:120]) diff --git a/modules/disk-load/cmd/disk-load/cpu_test.go b/modules/disk-load/cmd/disk-load/cpu_test.go index 07799355..748e8e3c 100644 --- a/modules/disk-load/cmd/disk-load/cpu_test.go +++ b/modules/disk-load/cmd/disk-load/cpu_test.go @@ -196,9 +196,10 @@ func TestCPUTopRanksAUnitsProcesses(t *testing.T) { f.file("/proc/13/stat", "13 (deep) S 1 1 1 0 -1 0 0 0 0 0 0 0 0 0 20 0 4 0 1 1 1\n") f.file("/proc/10/cmdline", "/usr/bin/firefox\x00--new-window\x00") f.file("/proc/11/cmdline", "mysql\x00--password\x00hunter2\x00") - st(10, "firefox", 150, 40) // 75 % of one CPU over 2 s - st(11, "sh (x)", 40, 1) // 20 % - st(13, "deep", 10, 4) // 5 %, in the child cgroup + f.file("/proc/13/cmdline", "/usr/bin/tool --password hunter2 -x") // a rewritten title: one string, spaces, no NUL + st(10, "firefox", 150, 40) // 75 % of one CPU over 2 s + st(11, "sh (x)", 40, 1) // 20 % + st(13, "deep", 10, 4) // 5 %, in the child cgroup f.then("/sys/fs/cgroup/user.slice/session-c1.scope/cgroup.procs", "10\n11\n14\n") f.file("/sys/fs/cgroup/user.slice/session-c1.scope/app/cgroup.procs", "13\n15\n") f.file("/proc/15/stat", "15 (old) S 1 1 1 0 -1 0 0 0 0 0 0 0 0 0 20 0 1 0 1 1 1\n") @@ -211,7 +212,7 @@ func TestCPUTopRanksAUnitsProcesses(t *testing.T) { } top := out.(map[string]any)["top"].([]ProcessCPU) if len(top) != 3 || top[2].PID != 13 || top[2].CPUPct != 5 || top[0].PID != 10 || top[0].CPUPct != 75 || top[0].SharePct != 75 || top[0].Threads != 40 || - top[0].Command != "firefox: /usr/bin/firefox" || top[1].PID != 11 || top[1].CPUPct != 20 || top[1].Command != "sh (x): mysql" { + top[0].Command != "firefox: /usr/bin/firefox" || top[1].PID != 11 || top[1].CPUPct != 20 || top[1].Command != "sh (x): mysql" || top[2].Command != "deep: /usr/bin/tool" { t.Errorf("processes of the unit: %+v", top) } for _, p := range top {