根据进程ID获取进程名字
2017-03-01 15:34
363 查看
private static String processName() { // shell获取指定pid的进程的名字 // ps | grep pid | awk '{print $9}' String processName=null; try { int pid = android.os.Process.myPid();///获取进程的PID String command="ps | grep "+pid+" | awk '{print $9}'"; String res=ShellExe.run(command, 20); if (res!=null&&res.length()>0&&!res.contains("not found")&& !res.contains("nvalid") && !res.contains("Read-only") && !res.contains("Usage: mount")){ processName=res; }else{ command="ps | busybox grep "+pid+" |busybox awk '{print $9}'"; res=ShellExe.run(command, 20); if (res!=null&&res.length()>0&&!res.contains("not found")&& !res.contains("nvalid") && !res.contains("Read-only") && !res.contains("Usage: mount")){ processName=res; }else{ ////////使用ps命令过滤出pid的进程信息 command="ps"; res=ShellExe.run(command, 20); if (res!=null&&res.length()>0&&!res.contains("not found")&& !res.contains("nvalid") && !res.contains("Read-only") && !res.contains("Usage: mount")){ String[] processList=res.split("\n"); for(String process:processList){ if(process!=null&&process.contains(pid+"")){ String[] infoList=process.split(" "); processName=infoList[infoList.length-1]; return processName; } } } } } } catch (Exception e) { e.printStackTrace(); } return processName; }
相关文章推荐
- 根据进程ID获取经常名字 和 根据进程名字获取进程ID
- linux根据进程名字获取进程ID
- 根据进程名字获取id并kill
- 根绝exe名字获取进程ID
- linux 根据进程ID获取对应进程的信息
- linux 下根据进程名字获取进程的进程号PID
- VB6 根据进程ID(PID)获取窗体句柄
- 根据关键词获取进程ID然后杀掉进程
- 根据窗口ID获取进程PID
- 如何根据进程id获取该进程的主窗口句柄
- android 根据图片名字获取图片id
- VB6 根据进程ID(PID)获取窗体句柄
- delphi根据进程ID获取进程路径
- 获取iOS设备上所有的进程名字,以及进程的ID,
- VB6 根据进程ID(PID)获取窗体句柄
- 一个根据进程名字,返回进程id的命令
- Windows Minifilter驱动 - 获取进程ID, 进程名字和线程ID (5)
- 根据进程ID获取进程路径
- linux下根据进程名字获取PID,类似pidof(转)
- C++ Windows 下 根据进程名获取进程ID 以及该进程下所有窗口的句柄