Running process start time

前端 未结 4 2161
失恋的感觉
失恋的感觉 2021-01-14 02:55

I am using below code to get all currently running process\'s on device. How can I get running process start time?

    activityMan = (ActivityManager)getSyst         


        
4条回答
  •  庸人自扰
    2021-01-14 03:36

    With kotlin and API 21 the above code becomes

    @Throws(IOException::class)
    private fun getStartTime( pid:Int ) : Long { 
        val reader = BufferedReader(FileReader ("/proc/$pid/stat"));
        val stats = try {
            reader.readLine();
        } finally {
            reader.close();
        }
        val fieldStartTime = 20;
        val msInSec = 1000;
        try {
            val fields = stats.substring (stats.lastIndexOf(") ")).split(" ");
            val t = fields[fieldStartTime].toLong();
            val tck = Os.sysconf(OsConstants._SC_CLK_TCK);
            return (t * msInSec) / tck;
        } catch (e: NumberFormatException) {
            throw IOException (e);
        } catch (e: IndexOutOfBoundsException ) {
            throw IOException (e);
        }
    }
    

提交回复
热议问题