Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7940081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:16:55+00:00 2026-06-03T23:16:55+00:00

I have the following code, for getting application names from their PID. The shell

  • 0

I have the following code, for getting application names from their PID.
The shell command is (just to show it works from the shell prompt, I trimmed a lot of lines, they all look alike)

C:\android-sdk-windows\platform-tools>adb shell ps
USER     PID   PPID  VSIZE  RSS     WCHAN    PC         NAME
root      1     0     312    220   c009b74c 0000ca4c S /init
root      2     0     0      0     c004e72c 00000000 S kthreadd
root      3     2     0      0     c003fdc8 00000000 S ksoftirqd/0
root      4     2     0      0     c004b2c4 00000000 S events/0
root      27    1     740    316   c0158eb0 afd0d8ac S /system/bin/sh
system    28    1     812    292   c01a94a4 afd0db4c S /system/bin/servicemanager
root      29    1     3736   568   ffffffff afd0e1bc S /system/bin/vold
system    68    33    191096 38680 ffffffff afd0db4c S system_server
radio     131   33    147680 22868 ffffffff afd0eb08 S com.android.phone
app_25    134   33    148784 25740 ffffffff afd0eb08 S com.android.launcher
app_0     160   33    135560 20956 ffffffff afd0eb08 S android.process.acore
root      316   40    740    332   c003da38 afd0e7bc S /system/bin/sh
root      317   316   888    336   00000000 afd0d8ac R ps

My java code is:

private static Pattern pidPattern = Pattern.compile("(\\d+).+?\\s+[DNRSTZ]\\s+(.+)$");

private final Map<Integer, String> pidNames = new HashMap<Integer, String>();

private void getAppNames() {
    // Bad command: String commandLine = "adb shell ps";
    String line;
    try {
        Process process = Runtime.getRuntime().exec("ps");
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
        Matcher matcher;

        pidNames.clear();
        while((line = bufferedReader.readLine()) != null) {
            matcher = pidPattern.matcher(line);
            if(matcher.find()) {
                int pid = Integer.valueOf(matcher.group(1));
                String name = matcher.group(2);
                pidNames.put(pid, name);
                Log.i(TAG, "Pid=" + pid + " Name=" + name);
            }
        }
        bufferedReader.close();
        process.destroy();
    }
    catch (IOException e) {
        Log.e(TAG, "getAppNames failed", e);
    }
}

And I get the following messages:

05-14 17:09:00.220: E/BackTask(698): getAppNames failed
05-14 17:09:00.220: E/BackTask(698): java.io.IOException: Error running exec(). Command: [adb shell ps, android.com] Working Directory: null Environment: [ANDROID_SOCKET_zygote=10, ANDROID_BOOTLOGO=1, EXTERNAL_STORAGE=/mnt/sdcard, ANDROID_ASSETS=/system/app, ASEC_MOUNTPOINT=/mnt/asec, PATH=/sbin:/system/sbin:/system/bin:/system/xbin, ANDROID_DATA=/data, BOOTCLASSPATH=/system/framework/core.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/android.policy.jar:/system/framework/services.jar, ANDROID_PROPERTY_WORKSPACE=9,32768, ANDROID_ROOT=/system, LD_LIBRARY_PATH=/system/lib]
05-14 17:09:00.220: E/BackTask(698):    at java.lang.ProcessManager.exec(ProcessManager.java:226)
05-14 17:09:00.220: E/BackTask(698):    at java.lang.ProcessBuilder.start(ProcessBuilder.java:201)
05-14 17:09:00.220: E/BackTask(698):    at com.delta.app.BackTask.getAppNames(BackTask.java:180)
05-14 17:09:00.220: E/BackTask(698):    at com.delta.app.BackTask.doInBackground(BackTask.java:65)
05-14 17:09:00.220: E/BackTask(698):    at com.delta.app.BackTask.doInBackground(BackTask.java:1)
05-14 17:09:00.220: E/BackTask(698):    at android.os.AsyncTask$2.call(AsyncTask.java:185)
05-14 17:09:00.220: E/BackTask(698):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
05-14 17:09:00.220: E/BackTask(698):    at java.util.concurrent.FutureTask.run(FutureTask.java:137)
05-14 17:09:00.220: E/BackTask(698):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
05-14 17:09:00.220: E/BackTask(698):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
05-14 17:09:00.220: E/BackTask(698):    at java.lang.Thread.run(Thread.java:1096)
05-14 17:09:00.220: E/BackTask(698): Caused by: java.io.IOException: Permission denied
05-14 17:09:00.220: E/BackTask(698):    at java.lang.ProcessManager.exec(Native Method)
05-14 17:09:00.220: E/BackTask(698):    at java.lang.ProcessManager.exec(ProcessManager.java:224)
05-14 17:09:00.220: E/BackTask(698):    ... 10 more

The question is: What’s wrong? Permission denied? The process call itself?

EDIT:
Tried the line:

Process process = Runtime.getRuntime().exec(commandLine);

With the same IOException result

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T23:16:57+00:00Added an answer on June 3, 2026 at 11:16 pm

    When you run your command line within the Android OS, you shouldn’t execute “adb shell ps”; you should just execute “ps”!

    There’s no “adb” executable on the device side.

    Also, a better way to spawn a process is like so:

    process = Runtime.getRuntime().exec("ps");

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following ColdFusion code that is getting information from a database and
I have the following code that creates the meta-description. I'm getting a 0 as
I have the following in my code, but I'm not getting an alert message,
I have following code in my application: // to set tip - photo in
I have following code in my Application. Comments in my code will specify My
I have following code in my application. [self.navigationController pushViewController:x animated:YES]; It will push a
i have following code to show div on page <div id=all_users> <div id=user11 userid=11
I have the following code that is getting all the gmail id's that are
I have a simple application with the following code: FileInfo[] files = (new DirectoryInfo(initialDirectory)).GetFiles();
I have the following code in my application: [DllImport(user32.dll)] private static extern int GetWindowLong(IntPtr

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.