获取线程TiD与进程PiD


/**

        * Returns the identifier of this process's user.

        * 返回此进程的用户的标识符。

        */

        Log.e(TAG, "Process.myUid() = " + android.os.Process.myTid());

        /**

        * Returns the identifier of this process, which can be used with

        * killProcess and sendSignal.

        * 返回此进程的标识符,可用于进程和发送信号。

        */

        Log.e(TAG, "Process.myPid() = " + android.os.Process.myPid());

        /**

        * Returns the identifier of the calling thread, which be used with

        * setThreadPriority(int, int).

        * 返回调用线程的标识符,该标识符与StTeRead优先级(int,int)。

        */

        Log.e(TAG, "Process.myTid() = " + android.os.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.

        * 返回线程的标识符。ID是正长生成的关于线程创建,对于线程是唯一的,并且不会改变。

        * 在线程的生存期内,ID可以在线程已被终止。

        */

        //返回当前线程的id

        Log.e(TAG, "Thread.currentThread().getId() = " + Thread.currentThread().getId());

        //返回主线程的id

        Log.e(TAG, "getMainLooper().getThread().getId() = " + getMainLooper().getThread().getId());

        //返回当前应用的主线程id

        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.

        * 返回此活动正在执行的任务的标识符。这个标识符对于活动的生存期将保持不变。

        */

        //返回activity任务栈的id

        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).

        * 已分配给该应用程序的内核用户ID;这不是一个唯一的ID(多个应用程序可以有相同的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.

        * 此应用程序应运行的进程的名称。从“进程”属性,或如果没有设置,与PACKAGEName相同。

        */

        Log.e(TAG, "getApplicationInfo().processName = "  + getApplicationInfo().processName);

        /**

        * 得到当前activity的信息

        */

        Log.e(TAG, "Activity.toString:"+this.toString());


        new Thread(new Runnable() {

            @Override

            public void run() {

                //返回当前线程的id

                // TODO Auto-generated method stub

                Log.e(TAG, "Thread.currentThread().getId() = "

                        + Thread.currentThread().getId());

            }

        }).start();

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1. 简介 用户打开浏览器,其实就是打开了浏览器应用程序。那么什么是程序呢?我们常说浏览器是多线程的,JS 是单线...
    love丁酥酥阅读 3,555评论 0 6
  • 0.Android手机操作系统的四层架构? Applications , Application Framewor...
    lucas777阅读 7,908评论 0 16
  • 线程 操作系统线程理论 线程概念的引入背景 进程 之前我们已经了解了操作系统中进程的概念,程序并不能单独运行,只有...
    go以恒阅读 1,693评论 0 6
  • 又来到了一个老生常谈的问题,应用层软件开发的程序员要不要了解和深入学习操作系统呢? 今天就这个问题开始,来谈谈操...
    tangsl阅读 4,182评论 0 23
  • 当某个应用组件启动且该应用没有运行其他任何组件时,Android 系统会使用单个执行线程为应用启动新的 Linux...
    小芸论阅读 1,753评论 0 12