Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

If I have a piped command such as

   cat myfile | processor_application

where processor_application is something reading from standard in, in chunks, to process, is it possible to see how far through the file cat has got?

Possibly using lsof?


share|improve this question
Thank you for the answers so far! However, I should have been clearer: the command is already running. – wodow Jan 31 '11 at 17:08
Ah yes, then pv is not so handy. You may want to edit your original question to make that more clear. – Phil Hollenback Jan 31 '11 at 17:14
Actually, there are three great separate answers in this question now, so I will leave it as it is. – wodow Jan 31 '11 at 18:04
Summarising, they are: 1. Use pv (before you start) 2. Use lsof -o (if offsets are supported) 3. look at value of wchar on /proc/<PID>/io , for the known PID of the cat process – wodow Jan 31 '11 at 18:05
up vote 11 down vote accepted

You can use pv to do this e.g.

pv file | processor_application

As pv passes it's stdin directly to it's stdout you don't need to use cat.

Edit As your program is already running then find the PID of the cat process and then look at the contents of


which will tell you how many bytes it has written - wchar.

share|improve this answer
I only just saw your edit! This works perfectly given the absence of (i) pv in the chain, (ii) lsof -o working. Thanks! – wodow Jan 31 '11 at 18:03

Absolutely! Pipe Viewer does exactlty that. Just insert it in your pipeline:

cat myfile | pv | processor_application

You can optimize away the cat in the above example:

pv myfile | processor_application

Which has the advantage of providing an actual progress indicator, since pv can determine the size of the input directly. If you do use pv in the middle of a pipeline, you need to supply the file size yourself to get accurate progress:

input_process | pv -s 100M -p | processor_application

Check the website for more options to customize pv.

share|improve this answer
I like pv - when I remember to use it! Thanks. – wodow Jan 31 '11 at 17:10
I like pv when it's available :-) – voretaq7 Jan 31 '11 at 18:00
It is rather easy to insert pv into a pipeline by using mkfifo and gdb (four syscalls with gdb's p). – grawity Jan 31 '11 at 21:12
@grawity you can't tease up like that. Write up a real answer and demonstrate - I'm very curious now. – Phil Hollenback Jan 31 '11 at 21:24
Too much of a hack to be an answer, but here. – grawity Jan 31 '11 at 21:41

If the process is already running lsof has a size/offset column which may be helpful to you -- find the PID of the cat process you want to inspect and then lsof -o -p [PID].

If the process is not running yet, pv as others suggested is a good option (assuming your system has that utility).

share|improve this answer
This is the lsof option that I had looked at. But: what if lsof -o is not allowed or unavailable on the system? – wodow Jan 31 '11 at 17:09
If -o doesn't work on your system I think you're pretty much screwed with respect to using lsof :-/ (I assume you're running lsof as the user who launched the cat process, or as root?) – voretaq7 Jan 31 '11 at 17:14
Yes, tried both. I am searching for reasons lsof warns -o as not available now... – wodow Jan 31 '11 at 17:15
The lsof FAQ, mirrored at, implies in point/question that lsof -o is not possible on Linux! I assume this is over-broad, as other users appear to be using lsof -o – wodow Jan 31 '11 at 17:26

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.