答复: [Haskell-cafe] How to do this in FP way?
dons at galois.com
Tue Jun 17 11:56:31 EDT 2008
> > OK. Here it is.
> > I want to make a monitor tool for linux. It runs for a long time, and give
> > out a certain process's io stat per second. The way I get io stat is to read
> > from /proc/pid/io. But the data in this file is a total, I need to read it
> > first, then next second, read it again, and shows the difference, and go on.
> > So, what is your idea?
> import Control.Concurrent
> import Control.Monad
> main = go 0
> go st = forever $ do
> n <- read `fmap` readFile "/proc/pid/io"
> print (n - st) -- display difference
> threadDelay (10^6)
Oops, not 'forever' :)
go st = do
More information about the Haskell-Cafe