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

The *nix command lsof gives you a list of open files. Is anyone aware of a way that would also list how long a particular file has been open? Either by using lsof or any other command. I'm using CentOS 5.3 and unfortunately I can't install additional repositories so I'd have to work from the default CentOS repos.


share|improve this question

migrated from stackoverflow.com Jan 6 '12 at 16:05

This question came from our site for professional and enthusiast programmers.

Why do you need that? I have currently no idea how to achieve that with either lsof or any other utils, so maybe there's an alternative solution to your problem... – plaes Jan 5 '12 at 10:29
There's an (in house) application specific problem and one of our processes is keeping a file open, but I can't determine if it's doing this everytime it's called, therefore I'd like to see the age of each open file, i.e. file1 is open since 2012-01-01 00:00:00, file2 is open since 2012-01-02 00:00:00 etc. – Tamas Jan 5 '12 at 10:34
There are two things I could think of: strace -e open,close program or valgrind with the --track-fds=yes option. – plaes Jan 5 '12 at 10:39

If you have the pid, you can directly check in /proc/$pid/fd. It seems to be where file descriptors are created.

If you take a look at their creation date with a simple ls -lh, maybe you'll be able to know how long a particular file has been open.

share|improve this answer

A -- not very exact guess -- could be to use the pid provided by lsof and use ps to find out since when the program that opened the file is running. This is of course working only for files opened at program start, not for later opened files.

share|improve this answer

Your Answer


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