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 fd [open /proc/stat RDONLY] set infoLst [lrange [regexp -inline -all {\S+} [gets ${fd}]] 1 7] close ${fd} 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.