0

Currently I am developing one android application in which I have a file on sdcard and I have to find out process id of all process which are accessing this file.

Using the android.os.FileObserver we can know only whether the file is accessed by any process. But how to get process id of that process?

Dhaval
  • 553
  • 3
  • 9

1 Answers1

0

I don't think it's possible through Android SDK.

What you could be looking for is lsof (system) command. Unfortunately it's unavailable on most stock ROMs under Android 4.0. According to comment under similar question, there has been a patch for ICS to add basic lsof support. I have Galaxy Nexus running 4.0.3 and I see that lsof command is present on my phone. You could also install BusyBox to install lsof (or require user of your applicatiion to install it).

Assuming that you have lsof present on phone you could parse output running command:

Runtime.getRuntime().exec(new String[] { "lsof", pathToInterestingFile});
Community
  • 1
  • 1
vArDo
  • 4,408
  • 1
  • 17
  • 26