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?
Thanks!
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/proc/<PID>/io
which will tell you how many bytes it has written - wchar.
Absolutely! Pipe Viewer does exactlty that. Just insert it in your pipeline:
You can optimize away the
cat
in the above example: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:
Check the website for more options to customize pv.
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 thenlsof -o -p [PID]
.If the process is not running yet,
pv
as others suggested is a good option (assuming your system has that utility).