Search code examples
fileshellpathpidlsof

How can I get pid and its executable path information through the file which is executed by this pid?


Based on information for a given file test.txt, I hope to get a pid and its executable path for a process that is operating on that file.

For example, if from the command line someone has run this:

$ cat test.txt

...then I want have something that will give output similar to this:

process 1123 bin/cat is using /home/sam/test.txt

Solution

  • If the file is still open, you can use:

    fuser /home/sam/test.txt