Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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

My problem is that with lsof -p pid I can find out the list of opened file of a process whose process id is pid. But is there a way to find out the file offset of each accessed file ?

Please give me some suggestions ?

share|improve this question
up vote 22 down vote accepted

On linux, you can find the position of the file descriptor number N of process PID in /proc/$PID/fdinfo/$N. Example:

$ cat /proc/687705/fdinfo/36
pos:    26088
flags:  0100001

The same file can be opened several times with different positions using several file descriptors, so you'll have to choose the relevant one in the case there are more than one. Use:

$ readlink /proc/$PID/fd/$N

to know what is the file to which the corresponding file descriptor is attached (it might not be a file, in this case the symlink is dangling).

share|improve this answer
Your answer is great. – Ta Thanh Dinh Mar 22 '12 at 16:18

lsof can do this, with the -o option.

Under Linux, it gets its information from /proc, so you can get it there as well.

share|improve this answer
It has been a long time since my last question, and I have not been here for a long time. Thank you for the answer. – Ta Thanh Dinh Apr 18 '12 at 9:21

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.