Version 2 of Get CPU Usage In Linux

Updated 2018-01-09 16:35:22 by CecilWesterhof

Created by CecilWesterhof.

I want to display my CPU usage. For this I need information (the first line) from /proc/stat. Here a proc that fetches this line, puts it in a easy to use dict, which also has a total added and returns it.

proc getStatCPU {} {
    set infoLst [lrange [getLineAsList /proc/stat] 1 7]
    lassign  ${infoLst} user nice system idle iowait irq softirq
    dict set statCPU user    ${user}
    dict set statCPU nice    ${nice}
    dict set statCPU system  ${system}
    dict set statCPU idle    ${idle}
    dict set statCPU iowait  ${iowait}
    dict set statCPU irq     ${irq}
    dict set statCPU softirq ${softirq}
    dict set statCPU total   [::tcl::mathop::+ {*}${infoLst}]
    return ${statCPU}
}

I will also post the script.

As always: comments, tips and questions are appreciated.