Android中的PID,UID,TID

来源:互联网 发布:最新流行歌曲网络歌曲 编辑:程序博客网 时间:2024/04/29 02:23

Source code:

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