2

When using the adb Monitor tool to read the Logcat, I like to filter out all everything but what directly affects the app. Trouble is, it's really hard to tell what the PID of your app. It easy enough if the app using Unity, but if it doesn't, It's almost impossible to use to tell.

So is there a ADB command that can tell what PID an app used?

4

You should be able to run a shell command from adb:

adb shell ps | grep your.app.name

And that will return details about your process. The second number will be the PID of your app. This is if grep is installed. If grep isn't installed, you can just run ps and it will dump all processes to your screen.

You can dump logcat to a file to retroactively look at processes (up to a point)
logcat > /sdcard/logcatDump.txt

However, logcat data is stored in memory so it will all be lost after a reboot.

  • I had the same thought in my mind and in fact wrote the answer until I realized that ps actually shows the PID of running processes. What OP asked here is the PID an app used. ps doesn't care for dead processes AFAIK. – Firelord May 7 '15 at 20:02
  • 1
    Ah, I missed that part. logcat is the only process that I know of that will have that data. It's stored in memory so you can't get it after a reboot. Question is modified to include that. – D. Gibbs May 7 '15 at 20:24
2

Simply do:

adb.exe shell pidof com.packagename.example

If you want to ensure only one PID is shown try:

adb.exe shell pidof -s com.packagename.example

protected by Community Aug 15 '18 at 13:29

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.