// Retrieves the current reading position in a file of any process on linux

Rarely I cross-post messages but for me this information was like a revelation so … have patience.

Question

How to get the current reading position in a file of a process on your machine ?

This information can be useful in an avalanche of circumstances

  • you are importing 10G dump.sql into your new database
  • a friend is downloading your last recorded song (copyright free, obviously ;-) ) from your home web-server and you want to know how many bytes you must still send to him before you can turn off the laptop
  • how long you must wait before a grep command finishes its work

Right Answer

Use cat /proc/<process pid>/fdinfo/<file_handle>

Example

For a demonstration keep this micro-program readdy.c and compile it:

QR Code: URL of current page
QR Code: URL of current page start (generated for current page)
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 3.0 Unported