I have this code to check for cpuload:
Code: Select all
(define (read-proc-stat)
(setq procStat (open "/proc/stat" "read"))
(do-while (regex {cpu\d?} (read-line procStat))
(parse-stat-line (current-line)))
(close procStat))
Code: Select all
ERR: value expected in function read-line : procStat
called from user defined function read-proc-stat
called from user defined function draw-cpu-load
Code: Select all
(define (read-proc-stat)
(setq proc-stat (open "/proc/stat" "read"))
(println "open handle: " proc-stat)
(do-while (regex {cpu\d?} (read-line proc-stat))
(println (current-line)))
(close proc-stat))
(while true
(read-proc-stat)
(sleep 1000))
The difference with the "real" script is that I have a status script that loads a cpuload module which contains read-proc-stat function definition.
I wonder why same function gets a constant handle when I call it one way and an incremented one (in steps of 4) when I call it the other way.
I modified read-proc-stat like this:
Code: Select all
(define (read-proc-stat:read-proc-stat)
(if (nil? read-proc-stat:procStat)
(setq read-proc-stat:procStat (open "/proc/stat" "read")))
(do-while (regex {cpu\d?} (read-line read-proc-stat:procStat))
(parse-stat-line (current-line)))
(seek read-proc-stat:procStat 0))