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.


  • 1
    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
  • 2
    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.


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy