Determine how far through a file an already running process is
file, file-io, linux, process
Solution
On modern Linux kernels, you can get information on file descriptors held by a process, including the current offset, in `/proc/$pid/fdinfo/$fd`:
pos: 12345
flags: 0100000
Problem
I want to see how far through a file a process is. Or, to be more accurate: I want to know what part of a file a process is reading from. Now I could use something like the pv command, except that won't work since I want to do this on a process that is already running. Here are a couple of examples: Lets say a video is playing in vlc. I want to be able to tell from another program how far through the video vlc is. Or with dd. Lets say I am mirroring a HDD (I know this example has problems because someone would be foolish to start dd without pv if they want to track progress (I am a fool) and you can send the kill signal to the dd to get the current progress, but ignoring those two facts...). This could be used to show me the transfer progress. I saw that on some linux systems, you can use lsof -o to get the offset, but I don't know how to turn that piece of data (something that looks like this `0t1659509`) into a percentage of how far through the file a process is or if that is even possible at all. Plus, knowing more than one way of doing one thing is good.