Remove heading in ps output using arg
This commit is contained in:
parent
a65523dab6
commit
0647a4b433
@ -22,10 +22,10 @@ func (self *Proc) update() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Processes() []Process {
|
func Processes() []Process {
|
||||||
output, _ := exec.Command("ps", "-acxo", "pid,comm,pcpu,pmem").Output()
|
output, _ := exec.Command("ps", "--no-headers", "-acxo", "pid,comm,pcpu,pmem").Output()
|
||||||
strOutput := strings.TrimSpace(string(output))
|
strOutput := strings.TrimSpace(string(output))
|
||||||
processes := []Process{}
|
processes := []Process{}
|
||||||
for _, line := range strings.Split(strOutput, "\n")[1:] {
|
for _, line := range strings.Split(strOutput, "\n") {
|
||||||
split := strings.Fields(line)
|
split := strings.Fields(line)
|
||||||
pid, _ := strconv.Atoi(split[0])
|
pid, _ := strconv.Atoi(split[0])
|
||||||
cpu, _ := strconv.ParseFloat(split[2], 64)
|
cpu, _ := strconv.ParseFloat(split[2], 64)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user