swestrup: (Default)
swestrup ([personal profile] swestrup) wrote2009-02-10 02:25 am

(Obvious?) Linux Question.

I've got a process that I'd like to monitor that, in debug mode, will issue a semi-infinite list of debug messages to stout.  What I would like to do is have it run in the background and output to some sort of ring-buffer file that only keeps the last 100K or so of output. That way I can occasionally check in on it with a tail -f command without worrying about my hard drive filling with a single huge file.

So, is there such a ring-buffer utility in Linux. I simply assumed that such a thing would exist (after all, dmesg is a ring buffer), but I've not had any luck looking for it. So, does such a file utility exist, or not?
ext_290181: (Default)

[identity profile] dcoombs.livejournal.com 2009-02-10 03:10 pm (UTC)(link)
I'm not aware of one existing... but it would be pretty easy to write a program that reads stdin and keeps the last 1000 lines or so in a file, and then pipe the output of your other program into that.

*shrug*
ext_157608: (Default)

[identity profile] sfllaw.livejournal.com 2009-02-10 03:39 pm (UTC)(link)
The reason such a utility does not exist for on-disk storage is because this would be rather slow and also unsafe. Chopping off the front of a file means copying the entire file.

That's why logrotate exists.

If you want an in-memory ring buffer, then http://vrb.slashusr.org/ has what you want. Exposing this on disk as a fake-file would require some FUSE hacking, though.
ext_157608: (Default)

[identity profile] sfllaw.livejournal.com 2009-02-10 08:42 pm (UTC)(link)
If you think about how modern filesystems are implemented, this is a non-trivial operation.