Android – How to get the processName or packageName by using PID?

This code is a simplified version of Yaqub’s code. I use this as a static method in a Util class: public static String getAppNameByPID(Context context, int pid){ ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); for(RunningAppProcessInfo processInfo : manager.getRunningAppProcesses()){ if(processInfo.pid == pid){ return processInfo.processName; } } return “”; }

Find my own process ID in VBScript

mshta terminates itself immediately. Maybe it’s too late to achieve parent process id by using WMI service. So, I’d use something like this to eliminate concurrent script processes. Generate random things. Determine an application which could be installed on each system, never terminates by itself (e.g. command prompt with /k parameter). Start the application in … Read more

How do I find the process ID (pid) of a process started in java? [duplicate]

This guy calls out to bash to get the PID. I’m not sure if there is an java solution to the problem. /** * Gets a string representing the pid of this program – Java VM */ public static String getPid() throws IOException,InterruptedException { Vector<String> commands=new Vector<String>(); commands.add(“/bin/bash”); commands.add(“-c”); commands.add(“echo $PPID”); ProcessBuilder pb=new ProcessBuilder(commands); Process … Read more

See Android recent task executed by the user

int numberOfTasks = 1; ActivityManager m = (ActivityManager)this.getSystemService(ACTIVITY_SERVICE); //Get some number of running tasks and grab the first one. getRunningTasks returns newest to oldest RunningTaskInfo task = m.getRunningTasks(numberOfTasks).get(0); //Build output String output = “the last application you’ve executed is ‘”+task.id+”‘ and the PID is ‘”+task.baseActivity.toShortString()+”‘”; getRunningTasks RunningTaskInfo

get process name from process id (win32)

You have different option which you can use to receive exe names of currently running processes (process names like you wrote). The best way depends a little from the programming language which you use and from other requirements. For example you can use WMI. One other more old way is the usage of Performance Counters … Read more