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
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);
}
}