github.com/iDigitalFlame/xmt@v0.5.4/cmd/list_nix.go (about) 1 //go:build !windows && !js 2 // +build !windows,!js 3 4 // Copyright (C) 2020 - 2023 iDigitalFlame 5 // 6 // This program is free software: you can redistribute it and/or modify 7 // it under the terms of the GNU General Public License as published by 8 // the Free Software Foundation, either version 3 of the License, or 9 // any later version. 10 // 11 // This program is distributed in the hope that it will be useful, 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 // GNU General Public License for more details. 15 // 16 // You should have received a copy of the GNU General Public License 17 // along with this program. If not, see <https://www.gnu.org/licenses/>. 18 // 19 20 package cmd 21 22 import ( 23 "strconv" 24 25 "github.com/iDigitalFlame/xmt/data" 26 ) 27 28 func readProcStats(s string) (string, uint32) { 29 var ( 30 n string 31 p uint32 32 ) 33 for _, e := range data.ReadSplit(s, "\n") { 34 if len(n) > 0 && p > 0 { 35 return n, p 36 } 37 if len(e) > 6 && e[0] == 'N' && e[2] == 'm' && e[4] == ':' { 38 for i := 5; i < len(e); i++ { 39 if e[i] == ' ' || e[i] == 9 || e[i] == '\t' { 40 continue 41 } 42 n = e[i:] 43 break 44 } 45 } 46 if len(e) > 5 && e[0] == 'P' && e[1] == 'P' && e[3] == 'd' && e[4] == ':' { 47 for i := 5; i < len(e); i++ { 48 if e[i] == ' ' || e[i] == 9 || e[i] == '\t' { 49 continue 50 } 51 if v, err := strconv.ParseUint(e[i:], 10, 32); err == nil { 52 p = uint32(v) 53 break 54 } 55 } 56 } 57 } 58 return n, p 59 }