答复: [Haskell-cafe] How to do this in FP way?
Don Stewart
dons at galois.com
Tue Jun 17 11:48:58 EDT 2008
magicloud.magiclouds:
> 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?
Easy,
import Control.Concurrent
import Control.Monad
main = go 0
where
go st = forever $ do
n <- read `fmap` readFile "/proc/pid/io"
print (n - st) -- display difference
threadDelay (10^6)
-- Don
More information about the Haskell-Cafe
mailing list