PID 指进程ID.

PID是进程的身份标识,程序一旦运行,就会给应用分配一个独一无二的PID(ps:一个应用可能包含多个进程,每个进程有唯一的一个PID)

进程终止后PID会被系统收回,再次打开应用,会重新分配一个PID(新进程的PID一般比之前的号要大)

命令:adb shell  +  ps|grep(图1)   或   adb shell ps (图2)

图1:

图2:

UID 指用户ID.

UID在linux中就是用户的ID,表明时哪个用户运行了这个程序,主要用于权限的管理。而在android 中又有所不同,因为android为单用户系统,这时UID 便被赋予了新的使命,数据共享,为了实现数据共享,android为每个应用几乎都分配了不同的UID,不像传统的linux,每个用户相同就为之分配相同的UID。(当然这也就表明了一个问题,android只能时单用户系统,在设计之初就被他们的工程师给阉割了多用户),使之成了数据共享的工具。

命令:adb shell  cat  /proc/PID号/status(图3)

图3

因此在android中PID,和UID都是用来识别应用程序的身份的,但UID是为了不同的程序来使用共享的数据。

package com.inanwong.main;import android.app.Activity;
import android.os.Bundle;
import android.os.Process;
import android.util.Log;public class MainActivity extends Activity {private static final String TAG = MainActivity.class.getSimpleName();/** Called when the activity is first created. */@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);/*** Returns the identifier of this process's user.*/Log.e(TAG, "Process.myUid() = " + Process.myUid());/*** Returns the identifier of this process, which can be used with* killProcess and sendSignal.*/Log.e(TAG, "Process.myPid() = " + Process.myPid());/*** Returns the identifier of the calling thread, which be used with* setThreadPriority(int, int).*/Log.e(TAG, "Process.myTid() = " + Process.myTid());/*** Returns the thread's identifier. The ID is a positive long generated* on thread creation, is unique to the thread, and doesn't change* during the lifetime of the thread; the ID may be reused after the* thread has been terminated.*/Log.e(TAG, "Thread.currentThread().getId() = "+ Thread.currentThread().getId());Log.e(TAG, "getMainLooper().getThread().getId() = "+ getMainLooper().getThread().getId());/*** Returns the thread's identifier. The ID is a positive long generated* on thread creation, is unique to the thread, and doesn't change* during the lifetime of the thread; the ID may be reused after the* thread has been terminated.*/Log.e(TAG,"((getApplication().getMainLooper()).getThread()).getId() = "+ ((getApplication().getMainLooper()).getThread()).getId());/*** Return the identifier of the task this activity is in. This* identifier will remain the same for the lifetime of the activity.*/Log.e(TAG, "getTaskId() = " + getTaskId());/*** The kernel user-ID that has been assigned to this application;* currently this is not a unique ID (multiple applications can have the* same uid).*/Log.e(TAG, "getApplicationInfo().uid = " + getApplicationInfo().uid);/*** The name of the process this application should run in. From the* "process" attribute or, if not set, the same as packageName.*/Log.e(TAG, "getApplicationInfo().processName = "+ getApplicationInfo().processName);new Thread(new Runnable() {@Overridepublic void run() {// TODO Auto-generated method stubLog.e(TAG, "Thread.currentThread().getId() = "+ Thread.currentThread().getId());}}).start();}
}
Log information:
10-12 01:57:30.885: ERROR/MainActivity(253): Process.myUid() = 10032
10-12 01:57:30.885: ERROR/MainActivity(253): Process.myPid() = 253
10-12 01:57:30.885: ERROR/MainActivity(253): Process.myTid() = 253
10-12 01:57:30.885: ERROR/MainActivity(253): Thread.currentThread().getId() = 1
10-12 01:57:30.885: ERROR/MainActivity(253): getMainLooper().getThread().getId() = 1
10-12 01:57:30.885: ERROR/MainActivity(253): ((getApplication().getMainLooper()).getThread()).getId() = 1
10-12 01:57:30.885: ERROR/MainActivity(253): getTaskId() = 3
10-12 01:57:30.885: ERROR/MainActivity(253): getApplicationInfo().uid = 10032
10-12 01:57:30.885: ERROR/MainActivity(253): getApplicationInfo().processName = com.inanwong.main
10-12 01:57:30.914: ERROR/MainActivity(253): Thread.currentThread().getId() = 8

Android中的PID,UID,TID相关推荐

  1. Android中的PID,TID和UID

    pid 是process进程id , uid 是user 用户id: 如果你是root,那么你的uid就是0,0为最高权限: 可以通过pid找到这个进程的uid,没有试过通过Uid找到所有Pid,大家 ...

  2. linux中进程pid,线程tid以及线程pid

    进程pid 进程pid(进程ID),每个进程在系统中都有一个唯一·的非负整数表示的进程ID,用getpid() 获取进程ID. 线程tid 线程tid(线程ID),每个线程在所属进程中都有一个唯一的线 ...

  3. ANDROID 中UID与PID的作用与区别

    ANDROID 中UID与PID的作用与区别 PID:为Process Identifier, PID就是各进程的身份标识,程序一运行系统就会自动分配给进程一个独一无二的PID.进程中止后PID被系统 ...

  4. Android中PID与UID的作用与区别

    PID:为Process Identifier, PID就是各进程的身份标识,程序一运行系统就会自动分配给进程一个独一无二的PID.进程中止后PID被系统回收,可能会被继续分配给新运行的程序,但是在a ...

  5. Android pid uid

    PID:为Process Identifier, PID就是各进程的身份标识,程序一运行系统就会自动分配给进程一个独一无二的PID.进程中止后PID被系统回收,可能会被继续分配给新运行的程序,但是在a ...

  6. linux中pid,tid, 以及 真实pid的关系

    1.pid,tid,真实pid的使用 进程pid: getpid() 线程tid: pthread_self() //进程内唯一,但是在不同进程则不唯一. 线程pid: syscall(SYS_get ...

  7. (Android7.0)Android获取PID、TID、UID

    注:文章可能完全摘录,参考或完全自创,如有摘录或参考,会在文章最下面备注参考资料的地址(而不一定是原始文章的地址).如有版权问题,请及时告知. 文章目的在于整理分享本人学到的知识,可能会有错误或表达不 ...

  8. Android中UID、GID和PID的讲解

    一.概述 在实际的开发中经常会碰到各种ID,这是由于在计算机的发展过程中,需要对程序执行的每一步做标记,通过这些标记的关联便于系统的统一管理.像PID.UID.GID.和EUID等,其实对于这些ID不 ...

  9. Android中startActivity中的permission检测与UID机制

    我们经常在一个activity中去start另一个activity,或者与另一个acitivity的结果进行交互(startActivityForResult).但有没有想过可能会出现的permiss ...

最新文章

  1. 软件项目开发无成熟框架套路之成本代价
  2. 用 Flask 来写个轻博客 (18) — 使用工厂模式来生成应用对象
  3. Centos netperf安装
  4. MySQL 数据库的操作 连接、新增、删除、选择数据库 命令行(带图)
  5. docker 和挂载文件一起打包成新镜像_Docker文件系统和数据卷
  6. 吉林省计算机二级考试题型,吉林省 | 2018年上半年全国计算机二级考试报考简章...
  7. rabitMQ-centos7安装
  8. 容器的综合应用:文本查询程序
  9. Linux下基于C/C++的Socket编程基础
  10. 【牛客 - 157B】凤凰(树上并查集,dfs)
  11. Gstreamer的一些基本概念与A/V同步分析
  12. 免费的音视频格式转换网站-ncm, qmc, mflac, mgg转mp3
  13. 为你的Intel(R) HD Graphics 显卡安装适合Premiere的驱动并解决“无法为此计算机验证正在安装的驱动程序“问题
  14. Struts2通配符和它的各种问题总结
  15. 熊猫烧香手工清除实验
  16. AI(adobe illustrator)怎么设置导出图片的像素尺寸
  17. 输入年份和月份输出该月有多少天python_输入年份和月份,输出该月有多少天,判断这一天是该年的第几天...
  18. systemverilog随机函数
  19. ADDA数模转换(PCF8591)
  20. 2019利兹大学计算机排名,2019软科世界大学学术排名利兹大学排名第101-150

热门文章

  1. ClassNotFoundException,某种类的缺失
  2. mappedBy和JoinColumn实质上指向的是同一个表即外键作为主键所在的表对应的实体
  3. C++实验六:继承,对BMP图片操作
  4. HDU - 2072 -- 单词数【set or 字典树】
  5. @Cacheable使用spring缓存
  6. 《微信》医保支付功能介绍
  7. Tableau:与Python集成
  8. Git(码云)配置精干版
  9. 使用8080并口协议驱动NT35510LCD显示屏
  10. web前端面试题之肉(css)